QGraphicsItem move parent instead of child...
Unsolved
General and Desktop
-
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); }
-
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 betweenpos()
andvalue
, then calculate the new pos ofmParentItem
by adding offset tomParentItem->pos()
.