PDA

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



bitChanger
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:

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

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

QGridLayout::update()
QDockWidget::update()
QDockWidget::updateGeometry()
QDockWidget::resize(sizeHint())
QDockWidget::resize(QGridLayout::sizeHint())

none of these help.

bitChanger
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.

bitChanger
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.