I'm struggling with QMainWindow
and QDockWidget
s, it seems a messy area.
I need the very simple thing: when application is closed, the arrangement of dockwidgets should be saved, and when application is opened, the arrangement should be restored.
The problem is that saveState()
/restoreState()
methods deal very strangely with central widget. There are several variants, and each has its own problems:
1. Central widget is set to, say, QPlainTextEdit
or QLabel
When state is restored, dockwidgets occupy as much horizontal space as possible, with thin central widget in the middle of left and right dockwidgets. Size and position of central widget is kept only vertically, but horizontal boundaries between dockwidgets and central widget is not saved.
2. Central widget is set to NULL
If I explicitly call:
this->setCentralWidget(NULL);
Then stateSave()
/stateRestore()
do work: state is saved and restored correctly, but for some strange reason user is unable to dock widgets at the top or bottom. Widgets can be docked only in one horizontal row, no matter how hard I try to dock it at the top or bottom.
3. No central widget
By "no central widget" I mean not touching central widget at all. For some reason, the behavior is different comparing to NULL
central widget:
State is saved and restored correctly, but if I make my window small, and then expand it again, then dockwidgets will remain small with huge unused area in the middle. So, user will have to resize them manually.
All of this looks very strange. Probably I'll have to go with "no central widget" variant, but I'm confused because I don't understand the behavior, maybe it's a bug, and then, behavior may change in future versions.
So, each of these ways has its own problems. If anyone can give me some clue on solving any of them, I'd be very glad.