#includeint main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget* window = new QWidget(); QVBoxLayout* layout = new QVBoxLayout(window); layout->addWidget(new QLabel("Widget 1")); layout->addWidget(new QLabel("Widget 2")); layout->addWidget(new QLabel("Widget 3")); layout->setSpacing(10); // Set spacing between widgets to 10 pixels window->show(); return app.exec(); }
#includeIn this example, we create a QGroupBox and add a QVBoxLayout to it. We then add three QPushButton widgets to the group layout and set a spacing of 20 pixels between them using the setSpacing() function. Finally, we add the groupbox to the main layout of the QWidget. Package library: Qt Widgets#include int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget* window = new QWidget(); QVBoxLayout* layout = new QVBoxLayout(window); QGroupBox* groupbox = new QGroupBox("Buttons"); QVBoxLayout* group_layout = new QVBoxLayout(groupbox); QPushButton* button1 = new QPushButton("Button 1"); QPushButton* button2 = new QPushButton("Button 2"); QPushButton* button3 = new QPushButton("Button 3"); group_layout->addWidget(button1); group_layout->addWidget(button2); group_layout->addWidget(button3); group_layout->setSpacing(20); // Set spacing between buttons to 20 pixels layout->addWidget(groupbox); window->show(); return app.exec(); }