QPushButton *button1 = new QPushButton("Button 1"); QPushButton *button2 = new QPushButton("Button 2"); QHBoxLayout *layout = new QHBoxLayout; layout->addWidget(button1); layout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Fixed, QSizePolicy::Fixed)); layout->addWidget(button2);
QPushButton *button1 = new QPushButton("Button 1"); QPushButton *button2 = new QPushButton("Button 2"); QHBoxLayout *layout = new QHBoxLayout; layout->addWidget(button1); layout->addStretch(); layout->addWidget(button2);In this example, a horizontal layout is created and two QPushButton widgets are added to it. A stretchable space is added between the buttons using addStretch function. This space will take up any extra space available in the layout. Package library: Qt