我是 Qt 的新手。我正在尝试创建一个具有以下布局的窗口,
--------------------------
| 按钮1 | 按钮2|
|------------------------------------|
|------- 图片--------|
-------------------------
我可以使用 QGridlayout 创建这个布局。看下面的代码,
QPushButton *button = new QPushButton(this);
QPushButton *nextButton = new QPushButton(this);
button->setText("Select new Image");
nextButton->setText("Next Image >>");
button->setMinimumSize(100,50);
nextButton->setMaximumSize(500,50);
button->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
nextButton->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
this->centralWidget = new QWidget(this);
this->centralWidget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
this->centralWidget->setGeometry(0,0,800,800);
QPalette Pal(palette());
Pal.setColor(QPalette::Background, Qt::black);
this->centralWidget->setAutoFillBackground(true);
this->centralWidget->setPalette(Pal);
this->layout = new QGridLayout (centralWidget);
this->layout->addWidget(button,0,0,1,1);
this->layout->addWidget(nextButton,0,1,1,1);
this->layout->addWidget(this->imageLabel,1,0,1,1);
this->layout->setRowStretch(0,1);
this->layout->setRowStretch(1,10);
但我想要的是图像应该占据更多空间,但图像只显示在窗口的下半部分。请看图片 您可以看到按钮和图片之间的空间。我想删除空间。
我尝试使用 setRowStretch 但这没有帮助。
PS:我正在使用带有 Qt 插件的 eclipse。还有一些我做出的选择可能很差。我是 Qt 的新手。非常感谢