#include#include #include #include // Create a QHBoxLayout and add widgets to it QHBoxLayout *layout = new QHBoxLayout; layout->addWidget(new QLabel("Name: ")); layout->addWidget(new QLineEdit); layout->addWidget(new QPushButton("Submit")); // Activate the layout on a parent widget QWidget *parentWidget = new QWidget; parentWidget->setLayout(layout);
#includeThis example creates a QHBoxLayout, adds two labels to it, and sets a stretch factor for each label to control their sizes. The first label will be twice as wide as the second label. The layout is then activated on a parent widget. The package library for QHBoxLayout is Qt Core.#include // Create a QHBoxLayout and add widgets to it QHBoxLayout *layout = new QHBoxLayout; QLabel *label1 = new QLabel("Label 1"); QLabel *label2 = new QLabel("Label 2"); layout->addWidget(label1); layout->addWidget(label2); // Set a stretch factor to control the widget sizes layout->setStretchFactor(label1, 2); layout->setStretchFactor(label2, 1); // Activate the layout on a parent widget QWidget *parentWidget = new QWidget; parentWidget->setLayout(layout);