子QGraphicsItem将事件(ItemIsMovable)移动到其父级

时间:2011-02-05 20:50:38

标签: qt qt4 move qgraphicsitem qgraphicstextitem

子QGraphicsItem如何移动其父项?

我设置子项的ItemIsMovable标志,当我尝试移动子项时,父项不移动,只有子项移动。


// 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); }

这样可行,但如果我选择多个项目,它只会移动鼠标下的项目。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

我通过在孩子的鼠标事件中调用父级鼠标事件来解决这个问题。

相关问题