PDA

View Full Version : How to put scaled QGraphicsItems next to eachother



profoX
2nd June 2008, 14:09
Hi all.

I'm having an issue with my QGraphicsItems. I want to put multiple QGraphicsItems next to eachother. What would be the best way to do that?

I used this code, which only works when the items are not transformed. But what should I use when the items are infact transformed? Because boundingRect() doesn't take the transformation into account.


for (int i = 0; i < itemList.size(); i++) {
itemList[i]->setTransformationMode(Qt::SmoothTransformation);
if (i > 0) itemList[i]->setPos(itemList[i-1]->x()+itemList[i-1]->boundingRect().width(), 0);
itemList[i]->setPos(itemList[i]->x(), (200-itemList[i]->boundingRect().height())/2.0);
}

I hope someone here can help me.... Thanks!

wysota
2nd June 2008, 15:21
All transformations are done relative to the (0,0) point, so if you place this point on the middle of the shared side of those items, they should be transformed correctly. You can also put both of them into an item group and transform the group and not individual items.

profoX
2nd June 2008, 15:49
Thanks for your answer, but I believe you are misunderstanding me.
Scaling works and looks fine.
The problem is that when I scale a QGraphicsItem,
that I can't find out where the next QGraphicsItem has to be located,
because QGraphicsItem::boundingRect().width() will return the width of the QGraphicsItem _without_ the scaling, so if I do a QGraphicsItem::scale(0.5, 0.5) on my first QGraphicsItem and I then call this for my second QGraphicsItem:

secondQGraphicsItem->setPos(firstQGraphicsItem->x()+firstQGraphicsItem->boundingRect().width(), 0);

the second QGraphicsItem will not be directly next to the first one, there will be a huge space in between them. How should I take the transformation into account?

wysota
2nd June 2008, 17:02
Use QGraphicsItem::mapTo*() family of methods to map to parent or the scene.

profoX
2nd June 2008, 17:40
Use QGraphicsItem::mapTo*() family of methods to map to parent or the scene.

I'm sorry, but I don't understand how that would help me. Could you explain a bit more how I would have to use it?

I need to know the real width() of the QGraphicsItem with the transformation taken into account. How should I use one of the mapTo*() functions to achieve that, or to achieve something similar? As far as I am aware, the mapTo*() functions also don't know about the transformation.

wysota
2nd June 2008, 19:28
I need to know the real width() of the QGraphicsItem with the transformation taken into account. How should I use one of the mapTo*() functions to achieve that, or to achieve something similar?

Map the rectangle of the item to the scene (world) coordinate space. Or simply use QGraphicsItem::sceneBoundingRect(), it does exactly the same.

profoX
3rd June 2008, 07:44
Map the rectangle of the item to the scene (world) coordinate space. Or simply use QGraphicsItem::sceneBoundingRect(), it does exactly the same.

Ok. Thanks for the extra information buddy! I'm now starting to understand how I have to do it :) This is the result so far:

Pretty satisfying for what I want to use it for.

http://85.17.105.113/~wesley/images/chimera_coverflow_demo.png