[PyQt] Signal this way

David Boddie david at boddie.org.uk
Wed Sep 30 00:20:28 BST 2009


On Tue Sep 29 02:47:11 BST 2009, pantheon wrote:

> I am creating <QAction> in a loop and adding it to menu.
>
> action = QtGui.QAction(QtGui.QIcon(iconFile), fileName, menu)
>                        menu.addAction(action)
>
> I need to connect this action to a python function in such a way that I
> should get <text> of QAction or instance of QAction object itself.

Connect its triggered() signal to a slot where you call sender() to obtain
the action object.

New-style connection syntax:

  action.triggered.connect(handleAction)

Then you can obtain the text from the action object:

  def handleAction(self):
      text = sender().text()

David


More information about the PyQt mailing list