You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Monday, April 25th 2011, 3:53pm

Center a QGraphicsPixmapItem at the center of the Scene

Hallo everyone

I just started programming with QGraphics\View.
I have generated all necessary things like View, Scene, SceneRect(-1000, -1000, 2000, 2000).
After that I implemented two lines(QGraphicsLineItems) one horizontaly, one vertically to find the center of the scene.
So far it looks quite good
Next I generated was a QGraphicsPixmapItem with a 40x40 pixmap.
Unfortunately the center of the pixmap doesn't match the center of the the crossing lines (should be 0,0).
I had to use setOffset(5,5) to place the pixmap in the scene's center but if I rotate the Item it tumbles around the scene's center

How do I get the pixmap in the center of the scene with setPos(0,0) without using an offset(which obviously doesn't work)

regards
hubipet

MasterBLB

Intermediate

  • "MasterBLB" is male

Posts: 188

Location: Poland/Wrocław

  • Send private message

2

Monday, April 25th 2011, 6:42pm

Try this Brother:

Source code

1
2
QRect &r=yaItem->boundingRect();
yaitem->setPos(centerX-r.width()/2,centerY-r.height()/2);

where centerX/Y are calculated offsets of centrum of the scene;
There are 10 kinds of people.Those who do understand the binary code,and those who do not ;)