qgraphicem在场景中的位置
QGraphicsItem position in the scene
我正在MAC OS X 10.9上使用QT 5.3 Widget应用程序,我遇到了一个问题。
在我的程序中,我有一个包含QGraphicsScene scene
的QGraphicsView view
,其中包含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]
如何获得物品相对于场景的坐标?
我已经阅读了一些关于这一点的教程,但我迷失在其中或不理解(英语不是我的母语)。
尝试使用setPos()
函数设置项目的位置。
您用来获取场景位置的函数是正确的scenePos()
,否则您也可以使用mapToScene()
。
相关文章:
- 将值指定给向量(2D)的向量中的某个位置
- 使用Unreal C++获取VR耳机的世界位置/方向
- 写入位置0x0000000C时发生访问冲突
- 如何将两个不同矢量的同一位置的两个元素组合在一起
- GL_SHADERSTORAGE_BUFFER位置是否与其他着色器位置冲突
- 如何使用cudaMallocManaged在指针位置初始化对象?(C++)
- 无法获取webot::PositionSensor对象中位置传感器的值
- 非常量变量只读位置的赋值
- 如何定义更改car类中car位置的方法
- 使用迭代器时如何访问对象在向量中的位置?
- 更改.cpp程序的输入文件中数据的位置会意外更改输出
- 求最大元素位置的分治算法
- 你好。。。id_public变量不应该给出结果为 81 和 86 吗?为什么它为两个派生类占用不同的内存位置?
- 为什么我的点没有在 OpenGL 中绘制鼠标所在的位置?
- 如何将元素添加到向量的字符串位置
- 如何选择在 csv 文件中输出的位置
- 无法打开 fstream C++文件,即使它与 .cpp 位于同一位置
- 如何在特定位置追加 json 文件
- 我的目标是编写一个程序来计算和存储字符串在字符数组中出现的位置
- OpenGL - 在 NDC 中计算位置适用于着色器,但不适用于'regular'程序