【问题标题】:Child QGraphicsItem move event (ItemIsMovable) to its parent子 QGraphicsItem 移动事件 (ItemIsMovable) 到其父
【发布时间】:2011-06-22 00:39:54
【问题描述】:

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

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

我该如何解决这个问题?

【问题讨论】:

    标签: qt qt4 move qgraphicsitem qgraphicstextitem


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2016-12-06
      • 2014-02-20
      • 1970-01-01
      • 2016-04-25
      • 1970-01-01
      • 2014-02-28
      • 2014-03-11
      • 2021-08-04
      • 1970-01-01
      相关资源
      最近更新 更多