how to make the QGraphicsScene resize automaticly
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...
Re: how to make the QGraphicsScene resize automaticly
Quote:
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.
Code:
//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.
Re: how to make the QGraphicsScene resize automaticly
Hi, I have the same issue - if anyone could answer, that would be swell.
Thanks
Re: how to make the QGraphicsScene resize automaticly
Someone -did- answer: Santosh Reddy, in 2013. So if his code didn't solve -your- issue, then you don't have the same issue.