Need save/restore QMainWindow minimized state
-
There are some plugins in my app - each one has main window derived from QMainWindow. I used saveState() and saveGeometry() methods to keep these windows same between app sessions. But no one of this methods gives info about window minimized/shown state. At least in Windows XP SP2. The windows geometry and docks inside windows are saved as well. But if I minimize plugin window - the next time it appeares on screen after restart. I need it will not appear if it was minimized in previous session.
I want suggest save "minimized" state with saveGeometry() cause it relates mostly to QWidget (not only QMainWindow can be minimized, but some other windowed class too).
Or I just missed something and this can be already done by other way?
Any opinion? -
Haven't done anything in that area recently, so I might remember wrong.
QSettings can be used to save the state of QWidget's "minimized" property. Then you just need to read settings on app startup and set the window state according to the saved value.
-
Here's a link to this property description: http://developer.qt.nokia.com/doc/qt-4.7/qwidget.html#id-85030a7f-dd06-4413-b7d7-00643c524901
-
The QWidget::showMinimized() is not suitable for me. I do not need to show but I need to restore minimized state. Window will be shown later. But I don't see something like QWidget::setMinimized(bool). Therefore I suggest include minimized state to ByteArray returned from QWidget::saveGeometry(). And restore this state in the QWidget::restoreGeometry().
-
Two possibilites:
- File a suggestion to the "bug tracker":https://bugreports.qt.nokia.com/secure/Dashboard.jspa
- Do the changes on your own and file a "merge request":http://www.qt-project.org/
-
[quote author="Gourmand" date="1321383818"]I just wanna discuss this before bugtracking.[/quote]
Well, I'm against this change then.
- I see no sense in letting QMainWindow::saveState() store the widgets state as there is no connection to its primary role (state of toolbars and dock widgets) and it is available to QMainWindow only. Such behaviour would be quite inconsistent and confusing.
- QWidget::saveGeometry() is responsible for saving a widgets geometry (size and position). The window state of a widget does not influence the geometry and vice versa - these are two independent properties of a widget of thus should have two independent setters and getters (otherwise I couldn't set one without the other).
- I do not expect that both, QMainWindow::restoreState() and QWidget::restoreGeometry(), modify the window state of a widget, as it has neither to do with a toolbar and dock widget state (state) or a widgets size and position (geometry).
- There is already an existing method for exactly this purpose: QWidget::windowState().
- Such a change might break existing applications.
What's the difference between
@
settings.setValue("geometry", widget.saveGeometry());
settings.setValue("state", widget.saveState());widget.restoreGeometry(settings.value("geometry").toByteArray());
widget.restoreState(settings.value("state").toByteArray());
@
and
@
settings.setValue("geometry", widget.saveGeometry());
settings.setValue("state", widget.saveState());
settings.setValue("windowstate", static_cast<int>(widget.windowState()));widget.restoreGeometry(settings.value("geometry").toByteArray());
widget.restoreState(settings.value("state").toByteArray());
widget.setWindowState(static_castQt::WindowState(settings.value("windowstate").toInt()));
@
besides an additional line of code that would justify these serious changes?