[PyQt] QGraphicsObject - Possible regression in PyQt5

Ales Erjavec ales.erjavec324 at gmail.com
Wed Feb 10 11:38:05 GMT 2016

On Sat, Feb 6, 2016 at 11:29 AM, Phil Thompson
<phil at riverbankcomputing.com> wrote:
> On 4 Feb 2016, at 10:21 am, Ales Erjavec <ales.erjavec324 at gmail.com> wrote:
>> Hello,
>> There seems to be a regression in PyQt5 when using QGraphicsObject
>> in a pyqtSignal definition.
>> When a signal is defined in a QObject as `signal = pyqtSignal(QGraphicsObject)`
>> the resulting meta object method will have a signature of
>> 'signal(QGraphicsItem*)',
>> but in PyQt4 this would have been 'signal(QGraphicsObject*)'.
>> Worse when the signal is actually emitted with an instance of a QGraphicsObject
>> the receivers all get a None instead of the intended instance.
>> This worked in PyQt4.
> Should be fixed in tonight's snapshot.
> Thanks,
> Phil

Testing on OSX with Python 3.5 and PyQt 5.5.2-snapshot-d304857728a3
the signal signature is 'signal(QGraphicsObject*)' and the emitted
argument is not None,
but unfortunately is of a wrong type (QtWidgets.QKeyEventTransition).


from PyQt5 import QtWidgets, QtCore

print("Using PyQt", QtCore.PYQT_VERSION_STR)

class GraphicsObj(QtWidgets.QGraphicsObject):
    def paint(self, painter, option, widget):

    def boundingRect(self):
        return QtCore.QRectF()

class Obj(QtCore.QObject):
    signal = QtCore.pyqtSignal(QtWidgets.QGraphicsObject)

meta = Obj.staticMetaObject
method = meta.method(meta.methodCount() - 1)
print("signal's signature:", bytes(method.methodSignature()).decode("ascii"))
# -> 'signal(QGraphicsObject*)'

def log(item):
    print("signal did emit with:", item)

obj = Obj()
#obj.signal[QtWidgets.QGraphicsObject].connect(lambda item:
print("item:", item))

gitem = GraphicsObj()
# -> signal did emit with: <PyQt5.QtWidgets.QKeyEventTransition object at ...


Note: If I connect the `obj.signal` to a second slot (commented out in
the example code)
the process terminates with a segmentation fault

AleŇ° Erjavec

More information about the PyQt mailing list