QVBoxLayout *layout = new QVBoxLayout; QLabel *label = new QLabel("Hello, world!"); QPushButton *button = new QPushButton("OK"); layout->addWidget(label); layout->addWidget(button); setLayout(layout);
QHBoxLayout *layout = new QHBoxLayout; QPushButton *button1 = new QPushButton("OK"); QPushButton *button2 = new QPushButton("Cancel"); layout->addWidget(button1); layout->addWidget(button2); setLayout(layout);
QGridLayout *layout = new QGridLayout; QPushButton *button1 = new QPushButton("Button 1"); QPushButton *button2 = new QPushButton("Button 2"); QPushButton *button3 = new QPushButton("Button 3"); layout->addWidget(button1, 0, 0); layout->addWidget(button2, 0, 1); layout->addWidget(button3, 1, 0, 1, 2); setLayout(layout);
QFormLayout *layout = new QFormLayout; QLineEdit *lineEdit1 = new QLineEdit; QLineEdit *lineEdit2 = new QLineEdit; layout->addRow("First name:", lineEdit1); layout->addRow("Last name:", lineEdit2); setLayout(layout);These examples use the QLayout package from the Qt library.