I am not sure if it is possible to always keep the aspect ratio after scaling.
If the aspect ratio of the scene rect is not equal with the aspect ratio of item's bounding box, then you're out of luck.
Generally, the scale factors are as follows:
float sx = sceneRect.width()/boundingBox.width();
float sy = sceneRect.height()/boundingBox.height();
float sx = sceneRect.width()/boundingBox.width();
float sy = sceneRect.height()/boundingBox.height();
To copy to clipboard, switch view to plain text mode
Next, you must call:
svgItem->scale( sx, sy );
svgItem->scale( sx, sy );
To copy to clipboard, switch view to plain text mode
There might be needed a repositioning( to center the item in view), but only in practice you can see if it is really necessary.
If the aspect ratios don't match, and if you find it acceptable, you can pad the item with a certain color or pattern in the area where it does not fill the scene rect.
Regards
Bookmarks