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

tao4yu picture tao4yu · Dec 2, 2013 · Viewed 21k times · Source

I am new to PySide. I want to get the QPushButton obj (such as use it to get its text) in its clicked slot.

button = QtGui.QPushButton("start go")
button.clicked.connect(self.buttonClick)

def buttonClick(self):
    ... # How can I get the button  object?
    # print button.text()  how to get the text : 'start go' ?

Thanks!

Answer

qurban picture qurban · Dec 2, 2013

Here is what I did to solve the problem:

button = QtGui.QPushButton("start go")
button.clicked.connect(lambda: self.buttonClick(button))

def buttonClick(self, button):
    print button.text()