Hello all

Currently using Qt 4.8.2 X64 on Windows, but I also tried it on 4.8.1 on a debian machine.

I'm wondering how you save the maximized state and restore it properly. Currently I save the position and size when closing and restore that when starting again, but this doesn't work all that well. The window looks maximized (the size is correct) but it's a little out of position and not really in maximized state (you can press the maximize button again).

Code isn't much, saving would be:

Qt Code:
  1. QSettings settings(COMPANY_NAME, PRODUCT_NAME);
  2. settings.setValue("pos", pos());
  3. settings.setValue("size", size());
To copy to clipboard, switch view to plain text mode 

Restoring would be:
Qt Code:
  1. QSettings settings(COMPANY_NAME, PRODUCT_NAME);
  2. QPoint pos = settings.value("pos", QPoint(100, 100)).toPoint();
  3. QSize size = settings.value("size", QSize(1024, 600)).toSize();
  4. resize(size);
  5. move(pos);
To copy to clipboard, switch view to plain text mode 

I also tried the saveGeometry() and restoreGeometry() functions. This works, except for a problem on a dual screen system where the window is maximized on the wrong screen (the default screen) at startup. So I thought I'd simply save the maximized state with isMaximized() as a bool and restore it with showMaximized(), but had similar results as well. Other 3rd party applications (e.g. visual studio) do this correct on my system.

So what is the correct way of doing this?