PDA

View Full Version : QMainWindow ignores dynamically created, floating QDockWidget



stefanadelbert
2nd March 2010, 01:38
If I dynamically create a floating QDockWidget and then call QMainWindow::saveState, the dynamically created QDockWidget's details are not saved. However, if I dock the QDockWidget to the QMainWindow and then call QMainWindow::saveState, the QDockWidget's details are saved. The details are also saved if I float the QDockWidget again. Seems that actually docking the QDockWidget to the QMainWindow has some effect on the operation of QMainWindow::saveState.

Has anyone come across this before?

Here is a code snippet from qmainwindowlayout.cpp:


void QMainWindowLayoutState::saveState(QDataStream &stream) const
{
#ifndef QT_NO_DOCKWIDGET
dockAreaLayout.saveState(stream);
#endif
#ifndef QT_NO_TOOLBAR
toolBarAreaLayout.saveState(stream);
#endif
}

This is called as part of QMainWindow::saveState. the dynamically created QDockWidget is considered as belonging to one of the four dock areas until it has actually been docked in one of them.

stefanadelbert
2nd March 2010, 02:06
Solved!

The problem was that I was calling QMainWindow::addDockWidget and specifying Qt::AllDockWidgetAreas, which is nonsense. I changed to calling QMainWindow::addDockWidget and passing Qt::LeftDockWidgetArea and then calling QDockWidget::setFloating(true). This means that the floating QDockWidget is at least associated with a dock widget area and is, as a consequence, considered when calling QMainWindow::saveState.

Rock.