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. 😂 How do you move a parent QGraphicsObject precisely by moving its child?

😂 How do you move a parent QGraphicsObject precisely by moving its child?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 1 Posters 406 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 enjoysmath
    #1

    The default is that the movements in the parent move the child because the child is in the parent's local coordinates always.

    I want the reverse of this.

    I know I can get it working with a position_changed signal, but I wanted to try it now with a sceneEventFilter. It's not working

    Insert obvious, naive code that listens for GraphicsSceneMousePress -and- GraphicsSceneMouseMove in event.type() to no avail.

    What is the canonical way to accomplish this?

    I would add that, the children in question are always within the parent's bounding rect.

    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
      from PyQt5.QtWidgets import (QGraphicsObject, QMainWindow, QGraphicsTextItem, 
                                   QApplication, QGraphicsScene, QGraphicsView)
      
      class A(QGraphicsObject):
          def __init__(self):
              super().__init__()
              #self.setFiltersChildEvents(True)
              
          def boundingRect(self):
              return self.childrenBoundingRect()
          
          def paint(self, painter, option, widget):
              painter.drawRect(self.boundingRect())
              
          
      class B(A):
          def __init__(self, text):
              super().__init__()
              self.text = QGraphicsTextItem(text)
              self.text.setParentItem(self)
              #self.text.installSceneEventFilter(self)
              
      class C(A):
          def __init__(self, text):
              super().__init__()
              self.b = B(text)
              self.b.setParentItem(self)
              self.setFlags(self.ItemIsMovable)
              
      if __name__ == '__main__':
          import sys
          app = QApplication([])
          
          wind = QMainWindow()
          wind.show()
          
          view = QGraphicsView()
          scene = QGraphicsScene()
          view.setScene(scene)
          wind.setCentralWidget(view)
          
          c = C('See?')
          scene.addItem(c)
          
          sys.exit(app.exec_())
      

      Here's the min example code, but it works... so...

      Any idea why this minimal example should work as I have described? What is causing it to work?

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

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

        K got it to work in my code now. Thanks, newbleets!

        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