PyQT5: What did this logical pass when the menu action is triggered?

So, I'm relatively new to Python, and I was trying to learn PyQt. I wanted to create a menu dynamically based on the contents of the list. I found an example that I adapted, and it looked like this:

for someText in myList: entry = QAction(someText,MainWindow) self.myMenu.addAction(entry) entry.triggered.connect(lambda menuItem=someText: self.doStuff(menuItem)) entry.setText(someText) 

A menu was created, but when a menu item was selected, doStuff () always gets the value False. So I changed this:

  for someText in myList: entry = QAction(someText,MainWindow) self.myMenu.addAction(entry) entry.triggered.connect(lambda bVal, menuItem=someText: self.doStuff(bVal,menuItem)) entry.setText(someText) 

and, of course, everything works as we would like. I still get False in bVal, which I just ignore.

I tried to look at the PyQt documentation, but the link refers to the C ++ documentation, and this is not obvious to me from what is happening.

I would like to understand what a logical value is and why, in my case, it is always False. I tried to change different things, but I could not find the script where it is True.

thanks

PyQT5.4, Python 3.4.2 on Windows.

-one
python pyqt5 pyqt
source share
1 answer

The C ++ documentation for the called signal should not be too complicated to understand:

void QAction :: triggered (bool checked = false)
...
If the action can be checked, the flag is true if the action is checked or false if the action is not checked.

Thus, the signal is emitted with a boolean parameter that indicates the status of the "checked" action, and this parameter menuItem default value for your menuItem argument.

+1
source share

All Articles