QHBoxLayout* layout = new QHBoxLayout; layout->addWidget(button1); layout->addStretch(); layout->addWidget(button2);
QHBoxLayout* layout = new QHBoxLayout; layout->addStretch(1); layout->addWidget(button1); layout->addStretch(2); layout->addWidget(button2);In this example, the stretchable spaces have different proportions. The first stretchable space will occupy one-third of the available space, while the second will occupy two-thirds. The package library used in this example code is the Qt GUI library.