Possible garbage collection problem with QGraphicsItem
I noticed a situation in PySide where try to remove a QGraphicsItem from a parentItem/scene and it doesn't get remove from the scene when i call setParentItem(None). When I remove another (added by myself) reference to the QGraphicsItem it does work. Some code:
def __init__(self, parent): super(Item, self).__init__(parent) self.select_target = self ...
item = Item(anotheritem)
item.setParentItem(None) #does not remove it from the scene, still gets hover events, etc.
however when I add:
self.select_target = None
and call that, the item is removed. I would expect both to have the same result, because of two reasons:
- i thought items where responsible for painting their children and setParentItem(None) removes the item as a child
- the self.select_target = self is a circular reference that should be detected by the garbage collector
found in docs: using setParentItem(0) .. 'None' in PySide .. remove item from parent item AND MOVES IT TO THE SCENE. Using
seems to work for me (now i think of it, might give a problem if parentItem or scene was never set, leave that as exercise). Still strange that self.select_target = None worked as well ....