在一個Qt例子中看到下列語句
QSplitter *splitter = new QSplitter(ui->managePage);
splitter->resize(700,360);
splitter->move(0,50);
splitter->addWidget(ui->toolBox);
splitter->addWidget(ui->dailyList);
splitter->setStretchFactor(0,1);
splitter->setStretchFactor(1,1);
QSplitter爲分割窗口類。
SetStretchFactor()方法用於設定可伸縮控件,它的第一個參數指的是控件的序號,控件序號按插入的先後次序從0開始進行編號;第二個參數爲大於0的值表示此控件爲可伸縮。
在這裏,就是說,toolBox和dailyList控件都是可拉伸的。
具體可以看Qt裏面的幫助文檔:
void QSplitter::setStretchFactor(int index, int stretch)
Updates the size policy of the widget at position index to have a stretch factor of stretch.
stretch is not the effective stretch factor; the effective stretch factor is calculated by taking the initial size of the widget and multiplying it with stretch.
This function is provided for convenience. It is equivalent to
QWidget *widget = splitter->widget(index);
QSizePolicy policy = widget->sizePolicy();
policy.setHorizontalStretch(stretch);
policy.setVerticalStretch(stretch);
widget->setSizePolicy(policy);