PDA

View Full Version : QDockWidget - dynamic size



ttvo
10th June 2009, 20:58
Hi all,

I have a QDockWidget (within a QMainWindow) that contains a custom outterWidget QWidget. The outterWidget has
1) an innerWidget QWidget which contains x number of widgets (QLineEdit and QLabel widgets) depending on the program condition
2) a horizontal line
3) a push button

for layouts, outterWidget is set to QGridLayout


QGridLayout *gridLayout = new QGridLayout(this);
gridLayout->setSpacing(5);
gridLayout->setMargin(2);
gridLayout->addWidget(innerWidget, 0, 0, 1, 3);
gridLayout->addWidget(ui.line, 1, 0, 1, 3);
gridLayout->addWidget(ui.runBtn, 2, 1, 1, 1);

innerWidget QWidget also has a QGridLayout that takes in an integer of how many row QLineEdit and QLabel to create


QGridLayout *mainLayout = new QGridLayout(this);
mainLayout->setSpacing(5);
mainLayout->setMargin(2);
for (int i=0; i<nParams; ++i)
{
int col = 0;
QLabel* label = new QLabel("test");
QLineEdit* lineEdit = new QLineEdit();
mainLayout->addWidget(label, i, col++);
mainLayout->addWidget(lineEdit, i, col++);
}


In my program, when the # of widgets within the innerWidget increases, the QDockWidget resizes probably, BUT when the # of widgets within the innerWidget decreases, the QDockWidget doesn't reduce its size probably so there are blanks on the . I have tried to called updateGeometry, update, resize etc ... but nothing helps.

Lykurg
10th June 2009, 21:15
Probably adjustSize() is working, not sure? And have you seen QFormLayout for your inner layout?

ttvo
12th June 2009, 01:05
adding "adjustSize()" on the QMainWindow seems to work. However, it introduces the unpleasant effect of the QMainWindow resizes.

The attached code has a QMainWindow that contains:
1) a label
2) a text box
3) 2 dock widgets

3a) one of them is empty, a place holder for some other stuff

3b) a dock widget with a scrollarea that contains an outter widget with:


3b1) a label & combo box
3b2) a dynamic inner widget
3b3) a label & combo box
I set the minimum size of this dockWidget to 180, 125 which should have enough room for the smallest size of the inner widget, ~80% cases. It seems to work fine EXCEPT for

Issue # 1) let say I run it with 1 widget to create dynamically in the inner widget, un-dock it, and re-dock it causes a change in the size of the scrollarea

Issue # 2) when un-dock, I'd like it to resize the dock widget so that no scrollbar is needed. Then when re-dock, I want it to go back to its original size

Thoughts? Thanks in advance.

Lykurg
12th June 2009, 07:07
A quick note: use the QDockWidget::dockLocationChanged() signal and save the geometry when the docking area is changed, so you can restore it afterwards, or adjust the size if the dock widget is floating.