[PyQt] QGraphicsObject - Possible regression in PyQt5

Ales Erjavec ales.erjavec324 at gmail.com
Thu Feb 4 10:21:52 GMT 2016


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.


from PyQt5 import QtWidgets, QtCore

class GraphicsObj(QtWidgets.QGraphicsObject):
    def paint(self, painter, option, widget):
        pass
    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(method.methodSignature())
# -> b'signal(QGraphicsItem*)'
# in PyQt4 this would have been 'signal(QGraphicsObject*)'

def assert_not_none(item):
    assert item is not None

obj = Obj()
obj.signal.connect(assert_not_none)

gitem = GraphicsObj()
# This will trigger the assertion error in the connected slot
obj.signal.emit(gitem)


Tested on:
    *OSX, Python 3.5, PyQt 5.5.1 (homebrew installed)
    * Debian, Python 3.4.2, PyQt 5.3.2


For reference, this is the equivalent code in PyQt4:


from PyQt4 import QtGui, QtCore

class GraphicsObj(QtGui.QGraphicsObject):
    def paint(self, painter, option, widget):
        pass
    def boundingRect(self):
        return QtCore.QRectF()


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


meta = Obj.staticMetaObject
method = meta.method(meta.methodCount() - 1)
print(method.signature())
# -> 'signal(QGraphicsObject*)'

def assert_not_none(item):
    assert item is not None

obj = Obj()
obj.signal.connect(assert_not_none)

gitem = GraphicsObj()
obj.signal.emit(gitem)


AleŇ° Erjavec


More information about the PyQt mailing list