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:
#include <QtGui>
{
Q_OBJECT
public:
layout
->addWidget
(new QLabel("A label",
this));
layout->addStretch();
setLayout(layout);
// setMinimumWidth(200); // experiment here if you want to constrain the size
}
};
Q_OBJECT
public:
central->setStyleSheet("* { background-color: blue; }");
setCentralWidget(central);
dw->setWidget(new Widget(dw));
addDockWidget(Qt::RightDockWidgetArea, dw);
}
};
int main(int argc, char *argv[])
{
MainWindow m;
m.resize(640, 480);
m.show();
return app.exec();
}
#include "main.moc"
#include <QtGui>
class Widget: public QWidget
{
Q_OBJECT
public:
Widget(QWidget *p = 0): QWidget(p) {
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(new QLabel("A label", this));
layout->addWidget(new QPushButton("A button", this));
layout->addStretch();
setLayout(layout);
// setMinimumWidth(200); // experiment here if you want to constrain the size
}
};
class MainWindow: public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *p = 0): QMainWindow(p) {
QWidget *central = new QWidget(this);
central->setStyleSheet("* { background-color: blue; }");
setCentralWidget(central);
QDockWidget *dw = new QDockWidget("DockWidget", this);
dw->setWidget(new Widget(dw));
addDockWidget(Qt::RightDockWidgetArea, dw);
}
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow m;
m.resize(640, 480);
m.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks