QDockWidget initial width

Phil Hannent picture Phil Hannent · Oct 10, 2008 · Viewed 13.6k times · Source

How do I set the initial width of a QDockWidget?

I have implemented the sizeHint function but what next?

Answer

David Dibben picture David Dibben · Oct 10, 2008

The documentation for QDockWidget says:

A QDockWidget acts as a wrapper for its child widget, set with setWidget(). Custom size hints, minimum and maximum sizes and size policies should be implemented in the child widget. QDockWidget will respect them, adjusting its own constraints to include the frame and title. Size constraints should not be set on the QDockWidget itself, because they change depending on wether it is docked; a docked QDockWidget has no frame and a smaller title bar.

So the size hint is taken from whatever you put in the dock widget. Have you tried setting the size of the QDockWidget's child?

But, I agree with Marius, the best thing to do is probably to use QSettings to save and restore the widths of all the dock windows when the application starts. Have a look at QMainWindow::saveState Apart from getting the data from saveState rather than from individual functions my save function looks very similar to the one given by Marius.