Save and restore maximized state
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:
Code:
QSettings settings
(COMPANY_NAME, PRODUCT_NAME
);
settings.setValue("pos", pos());
settings.setValue("size", size());
Restoring would be:
Code:
QSettings settings
(COMPANY_NAME, PRODUCT_NAME
);
QPoint pos
= settings.
value("pos",
QPoint(100,
100)).
toPoint();
QSize size
= settings.
value("size",
QSize(1024,
600)).
toSize();
resize(size);
move(pos);
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?
Re: Save and restore maximized state
I would store isMaximized() and then call showMaximized() while restoring (instead of setting the size and position).
Re: Save and restore maximized state
Thanks for the reply. As mentioned above, that is one of the things I've tried (see the bottom of my first post). But it results in the program starting maximized on the wrong screen.
Anyone with other ideas on how to solve it?
Re: Save and restore maximized state
So move it to the proper screen first.
Re: Save and restore maximized state
Yes I know that, but that is the question though. How do I detect the screen I'm on so I can save that information, and how do I move to the correct screen when restoring?
Re: Save and restore maximized state
Re: Save and restore maximized state
Thanks, that will solve it!
Re: Save and restore maximized state
This bug appears with Qt 4.8.0 version.
You should vote in qt bug tracker, and hope will be solved a day.......
https://bugreports.qt-project.org/browse/QTBUG-21371
It' s not a severe bug, but it's annoying, for exampel Qt designer is never restored on 2nd screen if in maximized state...