i'm working on a QT 5.3 Widget application on MAC OS X 10.9 and I've run into a problem.
In my program I have a QGraphicsView view
containing QGraphicsScene scene
contaning QGraphicsEllipseItem parent
which i use as parent (to keep track) for other QGraphicsEllipseItem
, lets call this last ellipse child
.
Now, I'd like to get position of the child
relative to scene
.
Whenever I try to get to the coordinates in the scene now, it returns [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]
How to get coordinates of the item relative to the scene?
I've read a few tutorials on the point but I'm getting lost in them or don't understand (english is not my native language).
Try by setting the position of the item using function setPos()
.
The function which your using to get the scene position is correct scenePos()
or else you can also use mapToScene()
.