// Create a QHBoxLayout QHBoxLayout* layout = new QHBoxLayout; // Add widgets to the layout layout->addWidget(button1); layout->addWidget(button2); layout->addWidget(button3); // Set the stretch factor of each widget layout->setStretchFactor(button1, 1); layout->setStretchFactor(button2, 2); layout->setStretchFactor(button3, 3);
// Create a QHBoxLayout QHBoxLayout* layout = new QHBoxLayout; // Add widgets to the layout layout->addWidget(button1); layout->addWidget(button2); // Set a stretch factor for the layout itself layout->setStretchFactor(1, 1);In this example, there are two buttons added to a `QHBoxLayout`. Instead of setting the stretch factor of the widgets within the layout, the stretch factor of the layout itself is set to 1. This means that the layout will take up more space, but the widgets within it will remain the same size. The `setStretchFactor` function is part of the `QtGui` package library.