views:

1144

answers:

2

I have a QMainWindow in a Qt application. When I close it I want it to store its current restore size (the size of the window when it is not maximized). This works well when I close the window in restore mode (that is, not maximized). But if I close the window if it is maximized, then next time i start the application and restore the application (because it starts in maximized mode), then it does not remember the size it should restore to. Is there a way to do this?

+1  A: 

I've encountered this problem as well.

What you can do: in addition to the window's size, save whether it's maximized or not (QWidget::isMaximized()).

Then next time you start the application, first set the size (QWidget::resize()) and then maximize it if appropriate (QWidget::showMaximized()). When it's restored, it should return to the correct size.

dF
+5  A: 

Use the QWidget::saveGeometry feature to write the current settings into the registry.(The registry is accessed using QSettings). Then use restoreGeometry() upon startup to return to the previous state.

Colin Jensen