Can't move QGraphicsEllipseItem
-
Hi, I'm trying to draw a circle, and the move it 150 pixels on the X axis. Here is the simplified code:
QGraphicsScene scene; QGraphicsEllipseItem circle; scene.addItem(&circle); circle.setRect(150,-0,200,200); circle.setPos(150,0); circle.moveBy(150,0); circle.setX(150);
The value 150 in the four lines do nothing. What's the correct way to move the item ?
-
circle.moveBy(150,0);
This moves your circle so
x == 300
.circle.setX(150);
This moves it back to
x == 150
.So it all works correctly (unless I misunderstood you).
-
All look correct. Can you show relevant parts of your real code? Perhaps there is something wrong there.
-
@sierdzio I just found out the problem. I was only experimenting with a single circle, and it seems that after the translation, the whole scene is moved so that its contents are centered.
When adding a second circle at 0,0 I now can notice the first one is indeed translated. The center of the scene is now the point between the circles.
Is there a way to fix the scene, so that it stops centering its contents ?