tags:

views:

76

answers:

1

I'm trying to get the positions and state of QDockWidgets saved/restored when the application is exited and relaunched. The flow in my main window is as follows:

restoreState(state.toByteArray());

// Dock widget gets created

restoreDockWidget(dockWidget);

This works great excepted for one thing: if dock widgets are closed when the application exits, they reappear into their last position the next time the application is run, while I'd expect them to have an initial hidden state. Is there something I missed about the usage of restoreDockWidget? Or should I handle the visible state of the dock widgets manually?

Update: Note that if I do as follows:

// Dock widget gets created

restoreState(state.toByteArray());

Then previously hidden widgets remain hidden. Unfortunately I cannot rely on this scheme as I have dock widgets that are created by plugins after the main window is restored.

Edit: seems to be fixed in latest Qt versions.

+1  A: 

Examining Qt's code (version 4.5.0) revealed the following:

bool QDockAreaLayout::restoreDockWidget(QDockWidget *dockWidget)
{
   ...
   dockWidget->show();
   // dockWidget->setVisible(!placeHolder->hidden);
   ...
}

(Note that QDockAreaLayout is a private Qt class that is used by QMainWindow).

I'm not sure why the line to set the dock widget's visibility is commented-out and replaced with a line to show the dock widget every time. I also couldn't find a bug in the Qt Bug Tracker for this; it seems like a bug to me.

It looks like you'll have to manage the visibility of the dock widgets manually.

RA
Thanks for the answer - I'll check out whether this is still the case with the current Qt Git. If it is, I think it's worth submitting the issue to the bug tracker as using restoreState() alone produces the expected behavior.
Gnurou