I think the normally window manager determines the initial position of the QMainWindow position on the desk top. I want to set the initial position myself. How is this done with Qt on Windows?
+8
A:
You can restore the window geometry with restoreGeometry(), and the state of docked elements with restoreState(), during the construction of your MainWindow...
QSettings settings("yourcompany", "yourapp");
restoreGeometry(settings.value("geometry").toByteArray());
restoreState(settings.value("state").toByteArray(),YOUR_UI_VERSION);
Then, if you override closeEvent(), you can save the state as follows:
QSettings settings("yourcompany", "yourapp");
settings.setValue("geometry", saveGeometry());
settings.setValue("state", saveState(YOUR_UI_VERSION));
YOUR_UI_VERSION is a constant you should increment when your UI changes significantly to prevent attempts to restore an invalid state.
Paul Dixon
2009-05-15 13:33:19
Exactly. .
Thomi
2009-05-27 08:02:23
+1: I had a hunch that something like that existed, but didn't know exactly how...
Torsten Marek
2009-08-18 16:07:01