Slots with arguments
Peter Bienstman <[email protected]> Fri, 10 Apr 2020 13:30:45 +0200
| Newsgroups | gmane.comp.python.pyqt-pykde |
|---|---|
| Message-ID | <CAMdxoPGQ+mn29X_7V7Z505OAq1UwS6Ds0WomHJS=v8m3XjRCRg@mail.gmail.com> |
Hi,
I'm building a pop-up menu where the number of entries depends on the
number of plugins a user installs at runtime. The code to deal with
these entries is very similar for all of them, so I want to use a
single slot, but with an argument.
According to some googling, something like this should work when
building the menu:
self.pronouncer_with_id = {}
if len(self.pronouncers):
id_ = 0
for pronouncer in self.pronouncers:
id_ += 1
pronouncer_action = QtWidgets.QAction(\
pronouncer.popup_menu_text, popup)
pronouncer_action.triggered.connect(\
lambda: self.pronounce(str(id_)))
popup.addAction(pronouncer_action)
My slot looks like this:
def pronounce(self, id_):
print(id_)
However, all the menu entries result in the argument 'id_' being the
same, namely the one corresponding to the latest entry added.
Any ideas?
Thanks!
Peter
_______________________________________________
PyQt mailing list [email protected]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt