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. QGraphicsItem move parent instead of child...

QGraphicsItem move parent instead of child...

Scheduled Pinned Locked Moved Unsolved General and Desktop
qgraphicsitem
2 Posts 2 Posters 581 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.
  • D Offline
    D Offline
    Dariusz
    wrote on last edited by
    #1

    Hey

    When I select child&move it, I'd like that the movement would happen to parent and child moved in relation to parent as a result.

    I'm trying to use itemChange function for it, but when I set pos on parrent the offset appear to be wrong... how can I adjust it ?

    QVariant myItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) {
        if (change == QGraphicsItem::ItemPositionChange) {
            qDebug() << value;
            mParentItem->setPos(value.toPointF()); // do I need some kind of offset between child pos & parent pos ? 
            return pos(); // cancel movement change on this item. 
        }
        return QGraphicsLineItem::itemChange(change, value);
    }
    
    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bonnie
      wrote on last edited by Bonnie
      #2

      Since QGraphicsItem::pos()

      Returns the position of the item in parent coordinates.

      So the item and its parent item are not in the same coordinate system.
      I think you should calculate the offset between pos() and value, then calculate the new pos of mParentItem by adding offset to mParentItem->pos().

      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