Thats a good point the painter does have a level of detail property that could be used for this.
My situation is rather simple since I'm just scaling then entire view, not individual items.
So when I'm using fitToView it scales the view to the sceneBoundingRect() of the item. The kicker is then if I want to zoom in or out from that point I have to start with a relative scale factor. Thats where the level of detail comes in play.
I also just took a peek at the QGraphicsView source and this is peppered throughout the code:
// Find the ideal x / y scaling ratio to fit \a source into \a target.
qreal xratio = targetRect.width() / sourceRect.width();
qreal yratio = targetRect.height() / sourceRect.height();
// Scale according to the aspect ratio mode.
switch (aspectRatioMode) {
case Qt::KeepAspectRatio:
xratio = yratio = qMin(xratio, yratio);
break;
case Qt::KeepAspectRatioByExpanding:
xratio = yratio = qMax(xratio, yratio);
break;
case Qt::IgnoreAspectRatio:
break;
...
painterMatrix *= QTransform()
.translate(targetRect.left(), targetRect.top())
.scale(xratio, yratio)
.translate(-sourceRect.left(), -sourceRect.top());
}
// Find the ideal x / y scaling ratio to fit \a source into \a target.
qreal xratio = targetRect.width() / sourceRect.width();
qreal yratio = targetRect.height() / sourceRect.height();
// Scale according to the aspect ratio mode.
switch (aspectRatioMode) {
case Qt::KeepAspectRatio:
xratio = yratio = qMin(xratio, yratio);
break;
case Qt::KeepAspectRatioByExpanding:
xratio = yratio = qMax(xratio, yratio);
break;
case Qt::IgnoreAspectRatio:
break;
...
painterMatrix *= QTransform()
.translate(targetRect.left(), targetRect.top())
.scale(xratio, yratio)
.translate(-sourceRect.left(), -sourceRect.top());
}
To copy to clipboard, switch view to plain text mode
Bookmarks