Note about Signals and PyQt4.

I keep making the mistake of sending PyQt_PyObjects instead of sending actual Qt4 objects on signals that are defined by Qt like that.

Bottom line:

If a signal has been defined by Qt, to send Qt objects, just copy and paste it, do not try to override it by exchanging the Qt objects for PyQt_PyObject.

This is because PyQt_PyObject is used to represent regular Python objects, therefore, original Qt4 classes will never emit signals under those weird signatures, Qt4 seems to be very strict on how it matches signals.

So when you see something like this on the documentation:

Qt Signals
void currentItemChanged (QTreeWidgetItem *,QTreeWidgetItem *)

Define your signal for example like this, and it will work:

SIGNAL_ITEM_CHANGED = SIGNAL('currentItemChanged (QTreeWidgetItem *,QTreeWidgetItem *)')

Do not do this, cause it won’t work:

SIGNAL_ITEM_CHANGED = SIGNAL('currentItemChanged (PyQt_PyObject, PyQt_PyObject)')

(Keep in mind PyQt_PyObject is used to represent Python objects only, and its useful only when YOU define and emit your own signals)

then connect it from a QTreeWidget item (or derived object) to a listener object’s method like this:

QObject.connect(myQTree,SIGNAL_ITEM_CHANGED,myListener.onItemChanged)

Your object’s listener method should look like this:

def onItemChanged(self, current, previous):
  #do what you gotta do, current and previous will be QTreeWidgetItems

Leave a Reply

Your email address will not be published. Required fields are marked *