I'm using solaris 5.8, Qt 4.2.2 and gcc 3.3 and have been trying to create a dialog with no margin or spacing for its child widgets. Unfortunately, things aren't going too well. It turns out that i only get the desired effect if i use a QWidget or QMainWindow instead of a QDialog. Could this be a bug in Qt?

Below is some code that produces two windows, one being a QDialog and the other a QWidget. The QDialog behaves incorrectly, insisting on drawing a margin and spacing for the child widgets, while the QWidget has the desired behavior.

Qt Code:
  1. #include <QApplication>
  2. #include <QDialog>
  3. #include <QVBoxLayout>
  4. #include <QPushButton>
  5.  
  6. int main(int argc, char** argv)
  7. {
  8. QApplication app(argc, argv);
  9.  
  10. //////////////////////////////////////////////////////////////////////
  11. // create a dialog with two buttons
  12.  
  13. QDialog diag;
  14. diag.setWindowFlags(Qt::Widget);
  15. diag.setWindowTitle("dialog");
  16. QVBoxLayout* layout = new QVBoxLayout();
  17. diag.setLayout(layout);
  18.  
  19. QSizePolicy policy(QSizePolicy::Minimum, QSizePolicy::Minimum);
  20. QPushButton* button1 = new QPushButton("button1");
  21. button1->setSizePolicy(policy);
  22. layout->addWidget(button1);
  23.  
  24. QPushButton* button2 = new QPushButton("button2");
  25. button2->setSizePolicy(policy);
  26. layout->addWidget(button2);
  27.  
  28. layout->setMargin(0);
  29. layout->setSpacing(0);
  30.  
  31. diag.show();
  32.  
  33. //////////////////////////////////////////////////////////////////////
  34. // create a widget with two buttons
  35.  
  36. QWidget widg;
  37. widg.setWindowTitle("widget");
  38. layout = new QVBoxLayout();
  39. widg.setLayout(layout);
  40.  
  41. button1 = new QPushButton("buttonA");
  42. button1->setSizePolicy(policy);
  43. layout->addWidget(button1);
  44.  
  45. button2 = new QPushButton("buttonB");
  46. button2->setSizePolicy(policy);
  47. layout->addWidget(button2);
  48.  
  49. layout->setMargin(0);
  50. layout->setSpacing(0);
  51.  
  52. widg.show();
  53.  
  54. return app.exec();
  55. }
To copy to clipboard, switch view to plain text mode 

Please, can any of you confirm the incorrect behavior? Or maybe i'm alone out here on Solaris island?

Thanks in advance!