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);
//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);
To copy to clipboard, switch view to plain text mode
Put this code in a slot connected to QGraphicsScene::changed() signal. That should appear as automatic.
Bookmarks