Unsolved save all dockwidgets' position and size when close app?
-
-
Hi,
In addition to @jsulm QMainWindow::saveState and its friend QMainWindow::restoreState.
-
not work well for DockWidget, especiall when some DockWidgets are tabified.
-
@opengpu
Hi
what happens if some DockWidgets are tabified ? -
the dockwidgets' position size even tabify-state are not save & restore correctly. i tried pos, size, geometry, state of MainWindow & Dockwidgets. work for MainWindows, but not for DockWidgets
-
Did you set an object name to all your dock widgets like explained in the documentation of QMainWindow::saveState.
-
no, i will try later.
so geometry & state are enough for MainWindow & DockWidget? no need to save pos/size, right? -
See Window Geometry for a discussion on why it is better to call QWidget::resize() and QWidget::move() rather than QWidget::setGeometry() to restore a window's geometry.
i saw this at https://doc.qt.io/qt-5/qsettings.html#restoring-the-state-of-a-gui-application
so should i use pos, size, state for MainWindow, DockWIdget? -
and how to reset to the default geometry and state ? the init state when the user first time open it without save any geometry or state. the mainwindow i showMax at the first time if no saved geom and state.
-
and should i setObjectName for all ui? include the LineEdit, Spinbox, Combox on QDockwidget, MainWindow? it seems impossible because there is too many...
so only gemo&state of MainWindow? or include gemo&state of DockWidgets, toolbar which is the widgets i want to save pos, size.
and what actually are saved when saveState? -
It's up to you to propose sensible defaults that you can revert to.
State and size/position are two distinct sets of properties that are complementary.
As for naming objects, it's explained in the documentation of QMainWindow::saveState that I already linked to.