Hi!
I have an object of QDialog. The dialog contains some widgets. Also there is an additional widget on the dialog (showing more details) that is visible/invisible with respect to the button "Show/hide more details" click. The widget locates in the bottom of the dialog. I want my dialog to resize itself when the widget "More details" have changed its visibility. I mean when I want to see more details my dialog gets longer (and vice-versa) but all widgets that are upper than the widget "More details" do not move at all. Now I use this code:
// This is a slot for the button "Show/hide more details"
void MyDialog::onMoreDetails(void)
{
bool visible = ui.widgetMoreInfo->isVisible();
QSize dialogSize
= this
->size
();
int dialogHeight = dialogSize.height(),
widgetHeight = ui.widgetMoreInfo->height();
ui.widgetMoreInfo->setVisible(!visible);
if (visible)
dialogSize.setHeight(dialogHeight - widgetHeight - 6);
else
dialogSize.setHeight(dialogHeight + widgetHeight + 6);
this->resize(dialogSize);
}
// This is a slot for the button "Show/hide more details"
void MyDialog::onMoreDetails(void)
{
bool visible = ui.widgetMoreInfo->isVisible();
QSize dialogSize = this->size();
int dialogHeight = dialogSize.height(),
widgetHeight = ui.widgetMoreInfo->height();
ui.widgetMoreInfo->setVisible(!visible);
if (visible)
dialogSize.setHeight(dialogHeight - widgetHeight - 6);
else
dialogSize.setHeight(dialogHeight + widgetHeight + 6);
this->resize(dialogSize);
}
To copy to clipboard, switch view to plain text mode
But it is not a universal method. Sometimes the dialog is resized okay but if one shrinks the dialog and clicks the button "More details" all upper widgets move. Maybe I should use layouts to resize?
P.S.: the number 6 is a kind of margin or padding.
Bookmarks