QGridLayout* layout = new QGridLayout; layout->addWidget(widget1, 0, 0); layout->addWidget(widget2, 1, 0); layout->addWidget(widget3, 2, 0); // Set the stretch factor for the second row to 2 layout->setRowStretch(1, 2);
QGridLayout* layout = new QGridLayout; layout->addWidget(widget1, 0, 0); layout->addWidget(widget2, 1, 0); layout->addWidget(widget3, 2, 0); // Set the stretch factor for all rows to 1 for(int i = 0; i < layout->rowCount(); i++){ layout->setRowStretch(i, 1); }In this example, we create a grid layout with three widgets in three rows. We use a loop to set the stretch factor for all rows in the layout to 1. This means that if there is extra space available in the layout, all rows will take up an equal share of that space. Package/Library: Qt