PDA

View Full Version : how to make the QGraphicsScene resize automaticly



reboot
5th April 2013, 08:05
I put a QGraphicsItem on a QGraphicsScene。When the item enlarge,the Scene will enlarge automaticly.
But the problem is when the item shrink, the Scene can not shrink automaticly.
who can give me some advice to make the QGraphicsScene resize automaticly whenever the item enlarge or shrink?
I will be very very grateful...

Santosh Reddy
5th April 2013, 11:37
who can give me some advice to make the QGraphicsScene resize automaticly whenever the item enlarge or shrink?
By default scene will grow when items are added or moved, by will not shrink when items are removed or moved. Scene should be explicitly shrinked using code like this.


//Calculates and returns the bounding rect of all items on the scene.
//This function works by iterating over all items, and because if this, it can be slow for large scenes.
QRectF rect = scene.itemsBoundingRect();
scene.setSceneRect(rect);


Put this code in a slot connected to QGraphicsScene::changed() signal. That should appear as automatic.

QtGatsby
7th May 2017, 17:43
Hi, I have the same issue - if anyone could answer, that would be swell.
Thanks

d_stranz
8th May 2017, 01:08
Someone -did- answer: Santosh Reddy, in 2013. So if his code didn't solve -your- issue, then you don't have the same issue.