【问题标题】:QGraphicsItem position in the sceneQGraphicsItem 在场景中的位置
【发布时间】:2014-09-20 21:42:28
【问题描述】:

我正在 MAC OS X 10.9 上开发 QT 5.3 Widget 应用程序,但遇到了问题。

在我的程序中,我有一个 QGraphicsView view 包含 QGraphicsScene scene 包含 QGraphicsEllipseItem parent,我将其用作其他 QGraphicsEllipseItem 的父级(以跟踪),我们将其称为最后一个椭圆 child

现在,我想获取child 相对于scene 的位置。

每当我现在尝试获取场景中的坐标时,它都会返回[0,0]

 QGraphicsItem * parent;
 QGraphicsScene * scene;
 ....
 parent = new QGraphicsEllipseItem(0,0,0,0);
 scene = new QgraphicsScene();
 scene.addItem(parent);
 ....
 new QGraphicsItem(12,12,10,10,parent);      //shown in the scene

 qDebug() << parent->childItems()[0].scenepos(); //returns [0,0]
 qDebug() << parent->childItems()[0].pos();      //returns [0,0]

如何获取项目相对于场景的坐标?

我已经阅读了一些关于这一点的教程,但我迷失在其中或不明白(英语不是我的母语)。

【问题讨论】:

    标签: c++ qt qgraphicsview qgraphicsscene


    【解决方案1】:

    尝试使用函数setPos() 设置项目的位置。

    你用来获取场景位置的函数是正确的scenePos()或者你也可以使用mapToScene()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多