pythonguis / feedback

Corrections & suggestions for Python GUIs tutorials on pythonguis.com
1 stars 0 forks source link

tutorial: Context menus by Signal #9

Open pying-around opened 7 months ago

pying-around commented 7 months ago

The alternate code is given as : class MainWindow(QMainWindow): def init(self): super().init() self.show()

    self.setContextMenuPolicy(Qt.CustomContextMenu)
    self.customContextMenuRequested.connect(self.on_context_menu)

def on_context_menu(self, pos):
    context = QMenu(self)
    context.addAction(QAction("test 1", self))
    context.addAction(QAction("test 2", self))
    context.addAction(QAction("test 3", self))
    context.exec(self.mapToGlobal(pos))

however Qt.CustomContextMenu is not defined until QT is added to the import statement

from PySide6.QtGui import QAction, Qt