#include#include /* ... */ QVBoxLayout *layout = new QVBoxLayout; QPushButton *button1 = new QPushButton("Button 1"); QPushButton *button2 = new QPushButton("Button 2"); layout->addWidget(button1); layout->addWidget(button2); /* ... */
#includeThis example creates a QVBoxLayout object and adds a QLabel widget to it. The addWidget() function is used to add the widget to the layout, along with some additional parameters. The second parameter is an integer that specifies the stretch factor. This determines how much space the widget should occupy in the layout. The third parameter is an alignment flag that specifies where the widget should be positioned within the available space. Package library: Qt.#include /* ... */ QVBoxLayout *layout = new QVBoxLayout; QLabel *label = new QLabel("Hello, world!"); layout->addWidget(label, 0, Qt::AlignBottom); /* ... */