Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to Fit QGraphicsScene in a QGraphicsView

Tags:

qt4

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.

like image 387
anj Avatar asked Jun 05 '12 05:06

anj


2 Answers

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.

like image 56
ssc Avatar answered Feb 03 '23 10:02

ssc


scaling the view like bellow doing what required:

view->scale(frameWidth / sceneWidth, frameHeight / sceneHeight);
like image 25
anj Avatar answered Feb 03 '23 10:02

anj