Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Compound QGraphicsItem object sometimes remains as a "ghost" after deletion, occasionally will crash Python
Forum Updated to NodeBB v4.3 + New Features

Compound QGraphicsItem object sometimes remains as a "ghost" after deletion, occasionally will crash Python

Scheduled Pinned Locked Moved Unsolved Qt for Python
1 Posts 1 Posters 38 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.
  • G Offline
    G Offline
    GrantH
    wrote last edited by GrantH
    #1

    Hi,
    This is my first Qt/PySide project, so please forgive the myriad newbie errors!

    I am building a model-based graph editor (nodes & edges) - think a GUI for networkx.
    The program maintains an 'abstract' mathematical model of the graph, a QListWidget of the elements in the graph, and QGraphicsScene of the nodes and edges graphically. Nodes are QGraphicsItems with text and an ellipse as children. Edges are also QGraphicsItems, with text, a line and an arrow as children. Adding and moving nodes and edges works fine. Edge end-points are moved as their connected node moves. Edges can successfully be moved from one node to another.
    When an edge is deleted, around 50% of the time, it works perfectly. The other ~50%, there is a ghost object left in the Scene. It is deleted from the abstract model, and from the QListWidget.
    If I print out all the graphicsView.items(), the 'deleted' edge is not shown in the list, but it is present in the drawn view. If you move a node so that the view has to resize, then the ghost often (but not always) goes away. I have tried scene.update() and scene.invalidate() to tidy things up, but it does not help. I have tried a delayed forced repaint, also without results
    QTimer.singleShot(500, lambda: self.ui.graphicsView.viewport().repaint())

    If I force a gc.collect the entire Python shell crashes without a trace, literally and figuratively! If doing an explicit
    self.Scene.render(painter, target=QRectF(), source=boundingRect)
    it will also crash Python.

    It seems that PySide6 has issues with object references? Threads here and here.

    Putting a strong reference on the child object, to 'hint' to the Python garbage collection as to when the object is still in use was helpful, but feels cludgy (even by newbie standards!)
    self.textItem.my_parent_item = self

    This is way beyond my abilities with Python garbage collection!

    I would love to be able to recreate a "short" code fragment for this, but I'm not sure where the issue is. The QGraphicsScene acts as the 'controller', sending updates to the List and Model. The node and edge objects have around 5 and 10 defined methods each (boudingRect, shape, paint, etc) My use of signals and slots is very limited - this is mostly calls at this point.
    The code, which is still the core the beginnings of the project, can be found on Github, here . I genuinely do not know which parts to extract to create the minimum code to reproduce the bug - it is somewhere in, or within, the interplay of GraphicsScene and GraphicsObjects.

    I am pretty sure I am not constructing the compound GraphicsObjects correctly, as I have some consistently odd selection and clipboard painting issues, and this may well be related.

    I have spent many hours chasing this, and would love any guidance anyone might have.

    Thanks in advance,
    Grant

    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