Constructing a QMainWindow object and displaying the window that object represents are two different things. At the very end of the constructor the main window is not visible.
What size does the undisplayed graphic view have in the undisplayed main window when you ask it to centre the view? When the main window is displayed and gets a concrete size so does the graphics view. How do you expect the graphics view content to move during this resize? Do you expect it to keep the same centre when it is resized during first display, but not when manually resized? The scroll bar granularity can also have an impact.
It's three lines of code to ensure the scene is centred on first showing:
MainWindow(...) {
...
QTimer::singleShot(0,
this,
SLOT(centreOnFirstDisplay
()));
}
public slots:
void centreOnFirstDisplay() { view->centerOn(0, 0); }
MainWindow(...) {
...
QTimer::singleShot(0, this, SLOT(centreOnFirstDisplay()));
}
public slots:
void centreOnFirstDisplay() { view->centerOn(0, 0); }
To copy to clipboard, switch view to plain text mode
Bookmarks