You have not asked Qt to do any sort of Layout Management so consequently it does not do any layout management. Widgets stay at the size and location you give them and nothing adjusts automatically. Here is a working example:
Qt Code:
  1. #include <QtGui>
  2.  
  3. class Widget: public QWidget
  4. {
  5. Q_OBJECT
  6. public:
  7. Widget(QWidget *p = 0): QWidget(p) {
  8. QVBoxLayout *layout = new QVBoxLayout(this);
  9. layout->addWidget(new QLabel("A label", this));
  10. layout->addWidget(new QPushButton("A button", this));
  11. layout->addStretch();
  12. setLayout(layout);
  13. // setMinimumWidth(200); // experiment here if you want to constrain the size
  14. }
  15. };
  16.  
  17. class MainWindow: public QMainWindow {
  18. Q_OBJECT
  19. public:
  20. MainWindow(QWidget *p = 0): QMainWindow(p) {
  21. QWidget *central = new QWidget(this);
  22. central->setStyleSheet("* { background-color: blue; }");
  23. setCentralWidget(central);
  24.  
  25. QDockWidget *dw = new QDockWidget("DockWidget", this);
  26. dw->setWidget(new Widget(dw));
  27. addDockWidget(Qt::RightDockWidgetArea, dw);
  28. }
  29. };
  30.  
  31. int main(int argc, char *argv[])
  32. {
  33. QApplication app(argc, argv);
  34.  
  35. MainWindow m;
  36. m.resize(640, 480);
  37. m.show();
  38. return app.exec();
  39. }
  40. #include "main.moc"
To copy to clipboard, switch view to plain text mode