View Full Version : How to get a QDockWidget to auto resize?

6th January 2006, 16:33
This QDockWidget contains a QGridLayout.

At run time a user can right click on some widgets in another area and add them to the grid of this dock widget. The widgets just overlap and look bad until the user manually resizes the dock widget. When they manually expand the dock widget to an acceptable grid look, that becomes the minimum size. I've also noticed that if you toggle the dock window visibility off and then on it will resize to an appropriate minimum size.

How can i get the dockwidget to auto resize? :confused:

6th January 2006, 16:38
Try QWidget::updateGeometry() or QGridLayout::update().

6th January 2006, 16:47
I've tried:


none of these help.

6th January 2006, 17:00
Ok, in my dock widget constructor i call setMinimumWidth(150). If i comment this line out then the dock widget auto resizes correctly.

This may be an acceptable solution. Now the only undesirable behavior is that when the dock widget contains nothing in the grid, the window width is small. This makes the window title scrunched up and looks funny.

6th January 2006, 17:10
As a place holder I added a QLabel to the gridlayout in the contructor with a welcome message. This solves the width issue and auto resize works correctly.