4. DO NOT save the geometry (you can see if the window state is maximized using QWidget :: isMaximized () before saving to the configuration file). Save the new isMaximised state value in the configuration file.
Another problem is this: the window will not only be maximized / minimized depending on its position on the screen, but depending on where most of the window is located. If 80% of the window is on screen1, but the upper left corner is on screen 2, the maximum window will be on screen1.
However, your idea is the best. After over an hour of Google (using QT5), I now use:
writeSettings:
settings.setValue("pos", pos()); if(!isMaximized()) settings.setValue("size", size()); settings.setValue("maximized", isMaximized());
readSettings:
if(settings.contains("pos")) move(settings.value("pos").toPoint()); if(settings.contains("size")) resize(settings.value("size").toSize()); if(settings.value("maximized").toBool()) setWindowState(windowState() | Qt::WindowMaximized);
source share