views:

149

answers:

2

Hi, In my project I am using QGraphicsView/QGraphicsScene stuff.

On my scene there will be regions that contains 2D graphics. Region count will be limited(Lets say 20)
Users can choose to display one or more regions.
If user choose to display one region I am going to show one region on scene
If user choose to display n regions I am going to show n regions on scene
I need a scaling logic to fit n regions on same scene.

How can I achieve this?

A: 

I believe you should use ensureVisible method.

Tadeusz A. Kadłubowski
A: 

QGraphicsView::fitInView() should do what you want:

QRectF bounding;
foreach(QRectF r, selectedRegionRects) {
    bounding |= r;
}
scene->fitInView(bounding, Qt::KeepAspectRatio);
Stephen Chu