我对 Qt 布局系统有疑问。第一张照片是我得到的,第二张是我想要的。我有一个垂直分离器和两个小部件。第一个小部件的扩展策略和拉伸因子为 1。第二个有最小高度策略,最小高度 100 和拉伸因子 0。开始后的结果应该是第二张图片,但实际上它是第一张图片,我需要手动向下拖动拆分器。问题出在哪里?
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QSizePolicy sp;
QSplitter * splitter = new QSplitter(Qt::Vertical);
splitter->setHandleWidth(1);
splitter->setChildrenCollapsible(false);
sp.setHorizontalPolicy(QSizePolicy::Expanding);
sp.setVerticalPolicy(QSizePolicy::Expanding);
splitter->setSizePolicy(sp);
QWidget * topWidget = new QWidget(splitter);
sp.setVerticalStretch(1);
topWidget->setSizePolicy(sp);
topWidget->setMinimumHeight(200);
QWidget * bottomWidget = new QWidget(splitter);
sp.setVerticalStretch(0);
bottomWidget->setSizePolicy(sp);
QTextEdit * edit = new QTextEdit();
edit->setFrameStyle(QFrame::NoFrame);
edit->setMinimumSize(0, 100);
sp.setVerticalPolicy(QSizePolicy::Minimum);
edit->setSizePolicy(sp);
QVBoxLayout * bottomWidgetLayout = new QVBoxLayout(bottomWidget);
bottomWidgetLayout->addWidget(edit);
bottomWidget->setLayout(bottomWidgetLayout);
splitter->setStretchFactor(0, 1);
splitter->setStretchFactor(1, 0);
this->centralWidget()->layout()->addWidget(splitter);
}