[PyQt] How to emit signal from QGraphicsRectItem

michael h michaelkenth at gmail.com
Thu Sep 3 23:14:35 BST 2015


>
>
>
>
> class RectItem(QGraphicsRectItem):
>     selectedChange = pyqtSignal(str)
>
> And I got error:
> test3.py, line 48, in <module>
>     rect.selectedChange.connect(message)
> TypeError: RectItem cannot be converted to PyQt5.QtCore.QObject in this
> context
>
> How to solve this?
>
> Zdenko
>
>
Zdenko,

QGraphicsRectItem does not inherit from QObject, while QGraphicsTextItem
does.

See:
http://stackoverflow.com/questions/4922801/adding-signals-slots-qobject-to-qgraphicsitem-performance-hit

The first answer alludes to either inheriting directly from QGraphicsObject,
or using multiple inheritance e.g. SomeItem(QGraphicsRectItem, QObject) but
i'm not sure this works from python.

The second answer listed hints at a signal emitting QObject that can emit
signals on behalf of the RectItems.

- mh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150903/b6b3fdd9/attachment-0001.html>


More information about the PyQt mailing list