Can you get the sender from a button clicked() event?
Dynamic Python binding for Qt Applications
Brought to you by:
florianlink,
marcusbarann
I'm curious as to whether there is a way to access the sender from a button click event. In C++ I've used the static method QObject::sender() to get the sender of the event but I can't seem to figure out how to do this in Python.
By the way, thanks for all the hard work you've done on PythonQt. It is a fabulous project.
Oh, I think I've figured out a way to do what I wanted. I can just use a closure. The inner function has access to objects in the parent scope so I can access the sender of the event that way.
QObject.sender() is not a static method, and you can call it from python.
However, depending on the connection type, sender() might not be set
properly. I noticed if I make the connectionType Qt.QueuedConnection it
works when sometimes Qt.DirectConnection does not.
On Tue, Dec 1, 2015 at 6:39 AM, Brad Elliott bradfordelliott@users.sf.net
wrote:
You can also use lambda functions, as described here:
http://stackoverflow.com/questions/27262288/qt-connect-slot-with-argument-using-lambda
Makes it quite slick!