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. The infamous "deleted graphics item reappears" bug is present in my app, how do I fix it?
Forum Updated to NodeBB v4.3 + New Features

The infamous "deleted graphics item reappears" bug is present in my app, how do I fix it?

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 177 Views
  • 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.
  • enjoysmathE Offline
    enjoysmathE Offline
    enjoysmath
    wrote on last edited by
    #1

    5e5a46fa-2386-4b01-a0f5-6e58862d086e-image.png

    That is the symptom pictured above. As you can see, those arrows will reappear, in particular when I'm dragging an object over them, and sometimes I believe when an arrow gets deleted but it's still attached to something.

    Anyway, what is a design pattern that I can use for a DeleteUndoCmd? I.e. whatever the deletion does, it must be undoable which means re-attaching arrows to nodes if need be.

    Anyway, I know about all that and coded my app robustly and even used a deleteLater() in there somewhere. However, as you can see items are not actually being removed from the scene (deleted).

    The PyQt5 code can be found here: https://github.com/enjoysmath/abstract-spacecraft

    Anyway, before I tackle this bug, I would like to know the proper / the only way to really delete something in a PyQt5 QGraphcisScene.

    https://github.com/enjoysmath
    https://math.stackexchange.com/users/26327/exercisingmathematician

    1 Reply Last reply
    0
    • enjoysmathE Offline
      enjoysmathE Offline
      enjoysmath
      wrote on last edited by
      #2

      Nevermind! Modifying DeleteItems with a _connectivity dictionary seems to have solved the problem.

      class DeleteItems(UndoCmd):
          Parent, Source, Dest = range(3)
          
          def __init__(self, items:list, canvas:LanguageCanvas):
              super().__init__()
              self._items = items
              self._canvas = canvas
              self._connectivity = {}
              
          def redo(self):
              for item in self._items:
                  if isinstance(item, Arrow):
                      self._connectivity[id(item)] = (item.parentItem(), item.source, item.destination)                
                      item.set_source(None)
                      item.set_destination(None)
                  elif isinstance(item, (Object, Text)):
                      self._connectivity[id(item)] = item.parentItem()
                  item.setParentItem(None)
                  self._canvas.removeItem(item)
                  
          def undo(self):
              for item in self._items:
                  if isinstance(item, Arrow):
                      parent, source, dest = self._connectivity[id(item)]
                      item.set_source(source)
                      item.set_destination(dest)
                  elif isinstance(item, (Object, Text)):
                      parent = self._connectivity[id(item)]
                  item.setParentItem(parent)
                  self._canvas.addItem(item)
      

      I honestly thought this would be much tougher to fix.

      https://github.com/enjoysmath
      https://math.stackexchange.com/users/26327/exercisingmathematician

      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