#includeQHBoxLayout *layout = new QHBoxLayout; QPushButton *button1 = new QPushButton("Button 1"); QPushButton *button2 = new QPushButton("Button 2"); layout->addWidget(button1); layout->addWidget(button2);
#includeIn this example, we create a QHBoxLayout and three QPushButton objects. We add all three buttons to the layout using the addWidget function. We then create a new QWidget and set the layout of the widget to be the QHBoxLayout, using the setLayout function. Package library: Qt Widgets module.QWidget *widget = new QWidget; QPushButton *button1 = new QPushButton("Button 1"); QPushButton *button2 = new QPushButton("Button 2"); QPushButton *button3 = new QPushButton("Button 3"); QHBoxLayout *hLayout = new QHBoxLayout; hLayout->addWidget(button1); hLayout->addWidget(button2); hLayout->addWidget(button3); widget->setLayout(hLayout);