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. Set rotation of QGraphicsItem using the position of its child

Set rotation of QGraphicsItem using the position of its child

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 377 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.
  • S Offline
    S Offline
    sasl
    wrote on last edited by
    #1

    I have a QGraphicsItem with a child - a small circle implemented as a QGraphicsEllipseItem - which I want to let the user drag around to set the rotation of the parent:

    0_1560175113600_Screenshot_20190610_155812.png
    (thin box on the left is the parent, red circle on right is the child)
    Ideally, the left object should rotate to follow the center of the right circle. I've set up the circle's itemChange event to grab the ItemPositionChange type and then emit a signal with the updated position, which is caught by the parent and used to calculate the parent's rotation:

    self.setRotation(math.degrees(math.atan2(newpos.y(), newpos.x())))
    

    (using Qt for Python, but this question probably doesn't depend on the choice of language)

    The problem I have is that by setting the parent's angle to the vector pointing towards the child, I implicitly update the child's coordinate system as well, so the child moves again in addition to the amount the cursor moved it:

    0_1560176363600_Screenshot_20190610_161810.png
    (the arrow shows the cursor drag path from the initial click)

    Does anyone have a good idea how to avoid this unwanted effect? I guess the obvious answer is to avoid making the red circle a child of the parent so that it doesn't use its coordinate system, but having the circle be a child of the other object makes sense for other reasons (it only exists because of the presence of the other object, etc.) so ideally I'd like to keep it.

    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