QMdiSubWindow Restore Geometry
G'day All,
I have a set of 10 or so QWidgets that are used in application main window code like:
Code:
QWidget * widget
= new ThingoWidget;
QMdiSubWindow * sw = m_ui->mdiArea->addSubWindow(widget);
sw->show();
to create MDI sub windows (each a different view of the same document) as needed. I'd like each type of sub-window to remember its position and size and restore that the next time it is opened.
I can capture the location on close by overriding the QWidget::closeEvent() in ThingoWidget to store the pos() and size() of the widget's parent QMdiSubWindow. I cannot use the ThingoWidget constructor to restore these values because the parent QMdiSubWindow does not exist until after the widget is constructed. Is there somewhere in the widget code I can restore the parent window geometry (slot or handler method), will it have to be done in the main window code above, or should I rewrite my widgets as QMdiSubWindow derivatives?
Any thoughts appreciated
Chris W
Re: QMdiSubWindow Restore Geometry
In the end I created a simple sub-class of QMdiSubWindow that has saveGeometry() and restoreGeometry() methods and a settable key for QSettings. I instantiate this manually and install the widget with setWidget().
As an added gotcha for newbies: The size of the QMdiSubWindow can be set before it is added to the MDI area, but its position cannot.