>First thing first, Signals and Slots, I don't fully follow these but this works so far. PyQt has some standard signals and slots that objects will "emit" on an event.
MyWidget.connect(MyButton, QtCore.SIGNAL('triggered()'), QtCore.SLOT('close()'))
In this instance I am "connecting" a QWidget to a MyButton, so when my button "Emits" the signal triggered() Then MyWidget executes the Qt close(), function which is a c function. Of course if you would prefere to execute your own function:
MyWidget.connect(MyButton.exit, QtCore.SIGNAL('triggered()'), self.MyFunction)
There you go now on a triggered signal you execute your function. Of course passing variables would be helpful. This involves two steps. Have your class emit a special signal.
class MyButton(QtGui.QPushButton): def __init__(self,label,parent=None): QtGui.QPushButton.__init__(self,label,parent) def mousePressEvent(self, event): self.emit(QtCore.SIGNAL("mysignal(int)"),5)
So I have overridden the standard mousePressEvent, instead of emitting the normal signal it runs my function. Which means, it does not do the standard, pushButton animation, so it is probably better to include a QtGui.QPushButton.mousePressEvent(self,event) inside. Then we handle the event here.
class MyButton(OriginalButton): __init__: MyWidget.connect(MyButton, QtCore.SIGNAL('MySignal(int)'), self.MyFunction) def MyFunction(self,var): print "this is the second argument of emit",var
And advatage of this is another object could also be 'connected' to the 'MySignal' and not use the variable as the argument. I think this is refered to as argument overloading.
This is a good resource for getting started, they show you some basic functionality and have some working examples.
This site is the class reference guide, they use a slightly different format than other python references, but one you get used to it, it works great.