PySide: base on the groupbox example of PySide-Exa

2019-08-20 06:01发布

问题:

This question already has an answer here:

  • PySide : How to get the clicked QPushButton object in the QPushButton clicked slot? 4 answers

Base on the groupbox example of PySide-Example, I add a clicked slot to the pushButton, such as:

    def createPushButtonGroup(self):
                 ...
        pushButton = QtGui.QPushButton("&Normal Button")
        pushButton.clicked(self.normalClick)
                 ...


    def normalClick(self):
        print self.sender.pushButton.text() 

But it issues an error: TypeError: native Qt signal is not callable.

回答1:

I can solve this problem like this:

...
pushButton.clicked.connect(lambda: self.normalClick(pushButton))
...

def normalClick(self, sender):
    print sender.text()

hope this helps you.