Or you can use the stretch parameter to QBoxLayout::addWidget() to apportion the available space in a known ratio:
#include <QtGui>
#include <QDebug>
Q_OBJECT
public:
layout->addWidget(list, 1); // allocate 1 unit to this
layout->addWidget(edit, 2); // and 2 units to this
central->setLayout(layout);
setCentralWidget(central);
}
public slots:
private:
};
int main(int argc, char *argv[])
{
MainWindow m;
m.show();
return app.exec();
}
#include "main.moc"
#include <QtGui>
#include <QDebug>
class MainWindow: public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *p = 0): QMainWindow(p) {
QWidget *central = new QWidget(this);
QListView *list = new QListView(this);
QLineEdit *edit = new QLineEdit(this);
QHBoxLayout *layout = new QHBoxLayout(central);
layout->addWidget(list, 1); // allocate 1 unit to this
layout->addWidget(edit, 2); // and 2 units to this
central->setLayout(layout);
setCentralWidget(central);
}
public slots:
private:
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow m;
m.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
How you tweak the layout depends on exactly what behaviour you want.
Bookmarks