PDA

View Full Version : QGraphicsItem position



zgulser
4th February 2009, 07:54
Hi,

I have an QGraphicsItem in which I have some other QGraphicsItem's. What I want to ask is, it seems(I printed the pos.x and pos.y values) the child items has automatically centered at their parent item's center. Is it true?

Nevertheless, one of my item is;

myItem.setRect(-7,-7,10,10);

and I once set the position of my item to 0,0 it does not seen it is on the center of it's parent item. Is that something wrong? or Is that for the reason that item's coordinates can only be integers?

Regards

jpn
4th February 2009, 16:20
Technically, QGraphicsRectItem::setRect() does not affect the position of the item. Visually it does, because it affects the bounding rect of the item.

zgulser
4th February 2009, 23:21
Hi,

Well ok..up to now, I understood that the position of an item can be changed by setPos(..).

AND just like you said, if I make QGraphicsItem.setRect(-7,-7,10,10) does it seems different than if I make QGraphicsItem.setRect(-5,-5,10,10) ? And Why?

For example, for QGraphicsItem.setRect(-5,-5,10,10), the rect drawn symmetrical around the
item's origin(4 equal subrectangles) but,
for QGraphicsItem.setRect(-7,-7,10,10), the rect drawn would not be symmetrical. Does it explain thw Why above?

Hope it's clear, Regards

wysota
5th February 2009, 00:27
If you don't use setPos() then the item's origin is aligned to its parent's origin therefore a rectangle beginning at (-7,-7) will be two units more to the left and up than the item beginning at (-5,-5).

zgulser
5th February 2009, 04:16
So I'm right.


Regards.

jpn
5th February 2009, 07:31
I was talking about the difference between QGraphicsItem::setPos() and QGraphicsRectItem::setRect(). Of course QGraphicsRectItem::setRect() affects the "visual position" of the item, but it won't change QGraphicsItem::pos.

wysota
5th February 2009, 09:33
By the way, item coordinates can be real values, not only integers.