[PyQt] Cannot reparent a QGraphicsItem after reimplementing itemChange

Ales Erjavec ales.erjavec324 at gmail.com
Fri Feb 19 11:01:06 GMT 2016


P.S. I just noticed that this is dependent on the order of execution.
Creating and
reparenting the graphics object BEFORE the signal
definitions/selectors, fixes the
problem.

On Fri, Feb 19, 2016 at 11:43 AM, Ales Erjavec
<ales.erjavec324 at gmail.com> wrote:
> Hello,
>
> This seems to be fixed in the daily snapshots (most likely by a fix for:
> https://www.riverbankcomputing.com/pipermail/pyqt/2016-February/036877.html),
> however since it took me a better part of 2 days to distill the
> problem into a reproducible
> test case, I think it is best to report this anyway
>
> Reimplementing a QGraphicsItem.itemChange would break reparenting the
> object to a QGraphicsObject instance. At first it seemed like a
> resurgence of:
> https://riverbankcomputing.com/pipermail/pyqt/2012-August/031818.html
>
> However a simple reproducible test case proved elusive. The problem
> only manifests after either defining a pyqtSignal with a QObject
> subtype (i.e. QAction,
> QAbstractButton, ...) or using the QObject subtype as the signal selector (e.g.
> `triggered[QAction]`). Specifying the C++ type by string name (e.g.
> `signal = pyqtSignal("QAction*")` or `triggered["QAction*"]` does not
> trigger this.
>
>
> #####
>
> from PyQt5 import QtWidgets, QtCore
>
>
> class GraphicsObj(QtWidgets.QGraphicsObject):
>     def itemChange(self, change, value):
>         if change == self.ItemParentChange:
>             print("parent change", value)
>         rval = super().itemChange(change, value)
>         if change == self.ItemParentChange:
>             print("\t->", rval)
>         return rval
>
>
> class Object(QtCore.QObject):
>     # A single signal definition triggers the bug
>     signal = QtCore.pyqtSignal(QtWidgets.QAction)
>     # This one does not
>     # signal = QtCore.pyqtSignal("QAction *")
>
>
> obj = Object()
> obj.signal[QtWidgets.QAction]  # This also triggers it
> obj.signal["QAction*"]  # This does not
>
>
> obj = GraphicsObj()
> objparent = GraphicsObj()
>
> obj.setParentItem(objparent)
> assert obj.parentItem() is not None
>
>
> #####
>
>
> Tested on:
>     *OSX, Python 3.5, PyQt 5.5.1 (homebrew installed)
>     * Debian, Python 3.4.2, PyQt 5.3.2
>
>
> AleŇ° Erjavec


More information about the PyQt mailing list