Actually, I found a solution using an article that I found here at QtCentre: Smooth Panning and Zooming
From that article I wrote:
void Layout::FitNetworkInView() {
//Get the rectangle of the visible area in scene coords
QRectF visibleArea
= mapToScene
( rect
() ).
boundingRect();
//Get map area
QRectF r
= myMap
->GetMapRect
();
//Scale the view
qreal scaleFactor = qMin( qAbs( visibleArea.width() / r.width() ), qAbs( visibleArea.height() / r.height() ) );
scaleFactor *= 0.9;
if ( scaleFactor > 0 ) {
scale( scaleFactor, scaleFactor );
} else {
scale( 1.0 / scaleFactor, 1.0 / scaleFactor );
}
SetCenter( r.center() );
}
void Layout::FitNetworkInView() {
//Get the rectangle of the visible area in scene coords
QRectF visibleArea = mapToScene( rect() ).boundingRect();
//Get map area
QRectF r = myMap->GetMapRect();
//Scale the view
qreal scaleFactor = qMin( qAbs( visibleArea.width() / r.width() ), qAbs( visibleArea.height() / r.height() ) );
scaleFactor *= 0.9;
if ( scaleFactor > 0 ) {
scale( scaleFactor, scaleFactor );
} else {
scale( 1.0 / scaleFactor, 1.0 / scaleFactor );
}
SetCenter( r.center() );
}
To copy to clipboard, switch view to plain text mode
Calling the function above will nicely fit my sites within the viewport.
/Kristian
Bookmarks