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:
Qt Code:
  1. // This is a slot for the button "Show/hide more details"
  2. void MyDialog::onMoreDetails(void)
  3. {
  4. bool visible = ui.widgetMoreInfo->isVisible();
  5. QSize dialogSize = this->size();
  6. int dialogHeight = dialogSize.height(),
  7. widgetHeight = ui.widgetMoreInfo->height();
  8.  
  9. ui.widgetMoreInfo->setVisible(!visible);
  10.  
  11. if (visible)
  12. dialogSize.setHeight(dialogHeight - widgetHeight - 6);
  13. else
  14. dialogSize.setHeight(dialogHeight + widgetHeight + 6);
  15.  
  16. this->resize(dialogSize);
  17. }
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.