You only need to compute the right scale factor, according to the size of the widget,.
try something like this :
void YourGraphicsView
::resizeEvent ( QResizeEvent * event
) {
const QSize& oldSize = event->oldSize();
const QSize& newSize = event->size();
//be aware of integer division and division by zero
double scaleFactorX = (oldSize.width ()>0) ? ((double)newSize.width())/oldSize.width ():1;
double scaleFactorY = (oldSize.height()>0) ?((double)newSize.height())/oldSize.height():1;
//sclae the view
scale(scaleFactorX, scaleFactorY);
}
void YourGraphicsView::resizeEvent ( QResizeEvent * event ) {
QGraphicsView::resizeEvent(event);
const QSize& oldSize = event->oldSize();
const QSize& newSize = event->size();
//be aware of integer division and division by zero
double scaleFactorX = (oldSize.width ()>0) ? ((double)newSize.width())/oldSize.width ():1;
double scaleFactorY = (oldSize.height()>0) ?((double)newSize.height())/oldSize.height():1;
//sclae the view
scale(scaleFactorX, scaleFactorY);
}
To copy to clipboard, switch view to plain text mode
But I am not sure that the behaviour will be correct for all cases.
Bookmarks