PDA

View Full Version : How to exclude an item from scene::itemsboundingrect() call ?



corrado1972
4th January 2012, 10:46
I want to exclude a single item from the computation of itemsboundingrect method: is this possibile? Maybe setting some flags?

This is my motivation: I have a qgraphicsscene with few items, the scene is zoomable, and the user is able to call fitInView with a button.
When I call fitInView, I'm using qgraphicsscene::itemsboundingrect instead of scene::scenerect(): I have no performance issues (there are too few items on the scene).
The item I want to exlude from computation is a ruler that is longer than the other items boundingrect, and it's causing a boundingrect bigger than the necessary.

thank you

wysota
10th January 2012, 17:09
Compute the rectangle manually.


QRectF rect;
foreach(QGraphicsItem *item, scene->items()){
if(exclude(item)) continue;
rect += item->sceneBoundingRect();
}