PDA

View Full Version : layout update problem



tuli
14th April 2013, 19:18
I have the following layout:


<vl>
<hl>
<otherstuff/>
</hl>
<hl2>
<tabwidget/>
</hl2>
<vl>

"Other stuff" includes a toggle button. If this button is toggled, i'd like to hide <tabwidget> or the entire <hl2> layout.
I cant seem to find a way to hide an entire layout, so i called setVisible() on the tabwidget:




ui.tabWidget->setVisible(ui.btnTog->isChecked());
this->updateGeometry();
this->update();
ui.horizontalLayout_5->update();

As you can see i called all update/refresh related methods afterwards, but the dialog layout doesnt change.
That means there's a big, empty unused spot where the tabwidget used to be.


What do i have to do to force the widget to recalculate its layout and consider the now hidden tabwidget?

wysota
14th April 2013, 21:04
Either your layouts are incorrect or you need to adjust size policies of other widgets to fill the space left by the tab widget (or both).

tuli
15th April 2013, 09:33
The other widgets are comboboxes and buttons, and hence dont grow vertically. Instead, i'd like the entire dialog to shrink to the size of said widgets.
i have no clue what else i could change, here a screenshot + a small sample project.
I'd be grateful if anyone could take a quick look! :)

89428943

wysota
15th April 2013, 10:20
QLayout::setSizeConstraint() with QLayout::SetFixedSize

tuli
15th April 2013, 10:54
thanks, that's better. But now the user cant re-size the dialog (which is desirable when the tabwidget is shown).
I'll experiment some more with this, thanks again!

wysota
15th April 2013, 11:16
thanks, that's better. But now the user cant re-size the dialog (which is desirable when the tabwidget is shown).

I can't think of a sane behaviour of a widget that both lets the user resize it and forces a specific size to be set. If you really want, you can just call resize(sizeHint()) but it doesn't make it any saner. If the user resizes the dialog and then you force your own size then the user might not like it.

tuli
15th April 2013, 14:56
It makes sense when the widget height is only changable by the user if the tableWidget is present. if it is not, the height is fixed and only the width is of interest to the user.

resize(sizeHint()) doesnt work, same for resize(minimumSize()). Both somehow give me a big empty spot where the tabwidget used to be.
interestingly, i obtained mixed result when calling resize(height(), 0).
if this i called from within the hide-button clicked() slot, it has no effect.

if, however, i call it from the clicked() slot of another button, it works perfectly!




void myform::bttong2clicked()
{
resize(width(), 0);
}


void myform::hidebuttonclicked()
{
ui.tabwidget ->setVisible(ui.hidebutton->isChecked());
if(!ui.hidebutton->isVisible()
resize(width(), 0);
return;
}



1) click hidebutton -> tabwidget disappears, empty space appears
2) click button2 -> empty space disappears, window has been resized correctly. Width is maintained.
3) click hidebutton -> tabwidget is shown again, window is resized apropriately


The problem is that i have to click two button to make it disappear. Any idea why it doesnt work when i call it from within hidebuttonclicked()?

wysota
15th April 2013, 18:35
It makes sense when the widget height is only changable by the user if the tableWidget is present.
If that's what you want then you can lift the size constraint on the layout when the table widget is visible and set it back otherwise.

tuli
15th April 2013, 18:58
yeah, but then the user cannot change the width of the widget when the tabwidget is hidden. The width is always changable, the height only when the tabwidget is visible.

Any ideas as to why my code above only works when called froma different slot? Because it does precisely what i want...