Details
Description
When using subclasses of QGraphicsItem, I have found that defining _getitem_ on a subclass will cause parentItem() to fail on a child item. For example:
from PySide2.QtWidgets import QGraphicsItem, QGraphicsRectItem class GraphicsItem(QGraphicsItem): def __getitem__(self, item): return None parent = GraphicsItem() child = QGraphicsRectItem(parent) print("Parent:", child.parentItem())
Running the above code generates the following error:
Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: object of type 'GraphicsItem' has no len()
The above example might seem contrived, but it was the result of about an hour of stripping down a larger application until it became clear what the problem was. So although the solution here is simple (remove _getattr_ from parent class), it is not at all obvious when this is encountered in a real application, and the result is very difficult to debug.
Attachments
For Gerrit Dashboard: PYSIDE-671 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
233284,3 | Add ownership condition for finite PySequences | 5.11 | pyside/pyside-setup | Status: MERGED | +2 | 0 |