Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Possible garbage collection problem with QGraphicsItem

Possible garbage collection problem with QGraphicsItem

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    farcat
    wrote on last edited by
    #1

    Hi,

    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:
    @
    class Item(QGraphicsItem):

    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:

    @
    def delete(self):
    self.select_target = None
    self.setParentItem(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

    UPDATE:
    found in docs: using setParentItem(0) .. 'None' in PySide .. remove item from parent item AND MOVES IT TO THE SCENE. Using

    @
    def delete(self):
    self.setParentItem(None)
    self.scene().removeItem(self)
    @

    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 ....

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved