I want to to fit a QGraphicsScene
in a QGraphicsView
with different dimensions, such that it will shrink or expand according to size of view, and there should be no any scrollbar.
This worked for me:
void MyGraphicsView::zoomToFit()
{
fitInView(scene()->sceneRect(), Qt::KeepAspectRatio);
}
You might want to adjust the scene rectangle to have a little margin; might look better, depending on your content.
scaling the view like bellow doing what required:
view->scale(frameWidth / sceneWidth, frameHeight / sceneHeight);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With