How can I make size of QGraphicsScene smaller?
Hi!
I have some problem...
There are a lot of items on the scene. Their size and arrangement can dynamically vary. But in this case the size of a scene always automatically increase. If the area which items take has decreased, the sizes of the scene does not vary. How is it possible to manage it?:confused:
Re: How can I make size of QGraphicsScene smaller?
After moving an item calculate the bounding rectangle all items occupy by using QRectF::united() on boundingRect()s and resize the scene accordingly.
Of course you may optimise calculations by comparing the original scene size and the element position prior and after a move.
Re: How can I make size of QGraphicsScene smaller?
Hey wysota,,,, he cud also use QGraphicsScene::itemsBoundingRect instead of calculating the united on boiunding rects himself , isnt it ???
Re: How can I make size of QGraphicsScene smaller?
Yes, of course. It could be a bit slower though, but unless there are many many items in the scene, it shouldn't matter.
Re: How can I make size of QGraphicsScene smaller?
Thanks, It's works =)
I used
Code:
scene->setSceneRect(0, 0, scene->itemsBoundingRect().width() + offset, scene->itemsBoundingRect().height() + offset);
It's slow, but I don't know other way:(
Re: How can I make size of QGraphicsScene smaller?
As I mentioned before, cache the result from a previous call and update it when an item is moved (based on the move itself).
Re: How can I make size of QGraphicsScene smaller?
Prefer this:
Code:
scene->setSceneRect(scene->itemsBoundingRect());
The itemsBoundingRect() function finds the actual bounding rect, and that might not be at (0, 0). If you force the scene rect to be (0, 0, width, height), you're bound to have items outside the scene.