Child QGraphicsItem move event (ItemIsMovable) to its parent

2.2k views Asked by At

How can a child QGraphicsItem move its parent item ?

I set the child item's ItemIsMovable flag and when I try to move the child item, the parent item does not move, only child item moves.


// child items's mouseMoveEvent
void TextDiagram::mouseMoveEvent(QGraphicsSceneMouseEvent *event){
     parentItem()->moveBy(event->pos().x() - lastPos.x() , event->pos().y() -lastPos.y() );
     QGraphicsItem::mouseMoveEvent(event);
}

void TextDiagram::mousePressEvent(QGraphicsSceneMouseEvent *event){ lastPos.setX( event->pos().x() ); lastPos.setY( event->pos().y() ); QGraphicsItem::mousePressEvent(event); }

This works but if I select more than one item, it only moves the item under the mouse.

How can I solve this ?

1

There are 1 answers

0
Baris Atamer On

I solved this by invoking parent's mouse events in child's mouse events .