Menu trigger parameter behavior

Gottfried Müller gottfried.mueller at gmx.de
Sat Aug 7 07:46:53 BST 2021


Hello,

the trigger function in a menu action get a boolean value when it
triggered without any parameters. I expected "None". Is this also in Qt
implemented or generated by PyQt5 only. The following example shows
this. The pressed function gets None like expected. The menu trigger
function gets False. It is a question only not really any issue (or?).

Gottfried

import sys
from PyQt5.QtWidgets import QApplication, QPushButton, QMenu

class ApplWindow(QPushButton):

     def __init__(self, parent=None):
         super().__init__(parent=parent)
         self.setText("Test trigger parameter")
         self.pressed.connect(self.btnPressed)
         menu = QMenu(parent=self)
         doSomething = menu.addAction("Menu triggered")
         doSomething.triggered.connect(self.menuTriggered)
         self.setMenu(menu)

     def btnPressed(self, param=None):
         print(". pressed param:", param)

     def menuTriggered(self, param=None):
         print(". triggered param:", param)

def main():
     appl = QApplication(sys.argv)
     applWindow = ApplWindow()
     applWindow.show()
     return appl.exec_()

if __name__ == "__main__":
     main()



More information about the PyQt mailing list