Why does complete understanding of Qt's scene graph coordinates lead no where?



  • def mouseMoveEvent(self, event):
          if self._placeItems:
              delta = event.scenePos() - event.lastScenePos()
              for item in self._placeItems:
                  item.setPos(item.pos() + item.mapToParent(item.mapFromScene(delta)))
          super().mouseMoveEvent(event)
    

    Approach: intuitively correct based on Qt's local/parent/scene coordinate system.
    Result: parented item shoots off into hyper space when you try to place it.

    def mouseMoveEvent(self, event):
           if self._placeItems:
               delta = event.scenePos() - event.lastScenePos()
               for item in self._placeItems:
                   item.setPos(item.pos() + delta)
           super().mouseMoveEvent(event)
    

    Approach: f*ck it, I'll just try passing in delta without transforming it!
    Result: The shit works! Idk why...

    Now multiply that by all the bugs you're going to run into... It starts to significantly effect debug time.



  • just thinking out loud, but it seems you don't have a complete understanding of what coordinates are local and what coordinates are global. if the scenegraph stuff works like other Qt widgets then each widget has its own localized coordinate system, independent of the parent.



  • This post is deleted!


  • @Kent-Dorfman

    Even knowing that. My code still seems correct, so how would you do the proper transformation?

    For even this causes a shoot of into hyperspace:

    def mouseMoveEvent(self, event):
           if self._placeItems:
               delta = event.scenePos() - event.lastScenePos()
               for item in self._placeItems:
                   p = item.parentItem()
                   if p: delta = p.mapFromScene(delta)
                   item.setPos(item.pos() + delta)
                   # BUGFIX: this doesn't work: item.mapToParent(item.mapFromScene(delta)))
           super().mouseMoveEvent(event)
    


  • @Kent-Dorfman yes, but if you have greatgrandparent-> grandparent-> parent -> item, then positioning of item is done in parent, so what I'm referring to is the the movement of item relative to scene, which by definition is a chaining of transformations. It's item.pos() + parent.pos() + grandparent.pos() + greatgrandparent.pos() for lack of better notation.


Log in to reply