[PyQt] Import of PyQt5.QtMultimediaWidgets borks QGraphicsObject wrappers
Phil Thompson
phil at riverbankcomputing.com
Thu Feb 4 10:17:59 GMT 2016
On 4 Feb 2016, at 9:27 am, Ales Erjavec <ales.erjavec324 at gmail.com> wrote:
>
> Hello,
>
> There seems to be a weird bug in PyQt5 w.r.t wrapping instances of
> QGraphicsObject subtypes, after importing QtMultimediaWidgets module
>
> The following code demonstrates this:
>
>
> from PyQt5 import QtCore, QtWidgets
>
> class Item(QtWidgets.QGraphicsObject):
> pass
>
> item = Item()
> itemparent = Item(objectName="abcd")
> item.setParentItem(itemparent)
> print(item.parentItem())
> #-> <__main__.Item object at ...>
> # so far so good
>
> import PyQt5.QtMultimediaWidgets
>
> print(item.parentItem())
> #-> <PyQt5.QtMultimediaWidgets.QGraphicsVideoItem object at ...>
> # not so good
> print(item.parentItem().objectName())
> #-> abcd
>
>
>
> Note that the itemparent variable's type remains untouched.
> But whenever it crosses the Qt5->PyQt5 boundary it is wrapped in a
> wrong type.
>
> Tested on:
> * OSX, Python 3.5, PyQt 5.5.1 (homebrew installed)
> * Debian, Python 3.4.2, PyQt 5.3.2
Your sub-class and QGraphicsVideoItem are returning the same value from type(). Re-implement type() in your sub-class to return (something like) UserType + 1.
Phil
More information about the PyQt
mailing list