Hi,

I am a relative newcomer to Qt - and am generally very impressed with it. I am using Qt v4.5.2 with VC++2008 plugin.

But I have been battling with a layout resizing issue for more than a week now.

I have designed a Dialog in Qt Designer (Ui file attached createvariable.ui - I had to simplify it a bit (too big!) to allow uploading ), with the intention to show or hide some widgets (contained in a Groupbox) on the Dialog depending on the active item in a Combobox. In both cases (widgets hidden or shown), the Dialog should resize to the minimum vertical size necessary - only the horizontal size needs to be expandable.

I therefore modified the Vertical Size policy of all the widgets that wasn't 'fixed' to 'minimum' (inlcuding the outer Dialog).

I instantiate the dialog as such:

Qt Code:
  1. try {
  2. //dialog and createVariable are class data members
  3. dialog = new QDialog(this);
  4. createVariable = new Ui::CreateVariableDialog;
  5. } catch (...) {
  6. if(dialog )
  7. delete dialog;
  8. QMessageBox::critical(this, tr("Error"), tr("Critical error
  9. allocating memory. Please close application and try again"));
  10. return;
  11. }
  12.  
  13. createVariable->setupUi(dialog);
  14.  
  15. createVariable->varFuncGroupBox->hide();
  16. dialog->adjustSize();
  17.  
  18. createVariable->okButton->setEnabled(false);
  19.  
  20. QRegExp rx("^(\\w+)$");
  21. QRegExpValidator regXValidator(rx, this);
  22. createVariable->varNameEdit->setValidator(&regXValidator);
  23.  
  24. //Initialise dialog widgets
  25. //Note: variable to be edited in editVariable()
  26. setVariableDialogItems();
  27.  
  28. //Var Type Combo Box
  29. connect(createVariable->varTypeComboBox, SIGNAL(currentIndexChanged(int)),
  30. this, SLOT(varTypeComboBoxIndexChanged(int)));
  31. //Var Function Class Combo Box
  32. connect(createVariable->varFuncClassComboBox, SIGNAL(currentIndexChanged(int)),
  33. this, SLOT(varFunctionClassIndexChanged(int)));
  34. //Var Name
  35. connect(createVariable->varNameEdit, SIGNAL(textChanged(const QString&)),
  36. this, SLOT(checkIfVarEditText(const QString&)));
  37.  
  38.  
  39. if(dialog->exec() == QDialog::Accepted){
  40. //Do some stuff...
  41. }
  42. if(dialog )
  43. delete dialog;
  44. if(createVariable)
  45. delete createVariable;
  46. dialog = NULL;
  47. createVariable = NULL;
To copy to clipboard, switch view to plain text mode 

This works fine, and the Dialog is correctly sized to minimum when opened. When the appropriate Combobox item is selected to show the
hidden widgets, the Dialog again resizes (expands) correctly. But when a Combobox item is then selected that should hide the widgets, the dialog is not resized back to 'minimum', and some widgets are spaced to take up the excess space. But now, if another Combobox item is selected that should also hide (or maintain the hidden) widgets, the dialog now resizes correctly (to minimum size).

The Slot handling the Combobox selections does the resizing as such:

Qt Code:
  1. void MainWindow::varTypeComboBoxIndexChanged(int index)
  2. {
  3. //Default settings
  4. createVariable->varFuncGroupBox->hide();
  5. //Do stuff...
  6. //Modify based on selection
  7. switch(index){
  8. case enHexArrayVector: //Do stuff...
  9. break;
  10. case enStringVector: //Do stuff..
  11. break;
  12. case enFunction: //Do some stuff, then..
  13. createVariable->varFuncGroupBox->show();
  14. }
  15. createVariable->varDefGroupBox->adjustSize();
  16. dialog->adjustSize();
  17. }
To copy to clipboard, switch view to plain text mode 

Any ideas on what I am doing wrong or not doing?
greatgatsby