Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
创建具有固定高度的Qt布局_Qt_Layout - Fatal编程技术网

创建具有固定高度的Qt布局

创建具有固定高度的Qt布局,qt,layout,Qt,Layout,我想创建一个包含两个布局的Qt窗口,一个固定高度的窗口包含顶部的按钮列表,另一个窗口使用布局填充剩余空间,布局垂直和水平居中,如下图所示 我应该如何布置我的布局/小部件。我尝试了一些嵌套水平和垂直布局的选项,但都没有效果尝试将粉红盒变成一个带有QHBoxLayout的QWidget(而不仅仅是一个布局)。原因是QLayouts不提供固定大小的功能,但QWidgets提供 // first create the four widgets at the top left, // and use Q

我想创建一个包含两个布局的Qt窗口,一个固定高度的窗口包含顶部的按钮列表,另一个窗口使用布局填充剩余空间,布局垂直和水平居中,如下图所示


我应该如何布置我的布局/小部件。我尝试了一些嵌套水平和垂直布局的选项,但都没有效果

尝试将粉红盒变成一个带有QHBoxLayout的QWidget(而不仅仅是一个布局)。原因是QLayouts不提供固定大小的功能,但QWidgets提供

// first create the four widgets at the top left,
// and use QWidget::setFixedWidth() on each of them.

// then set up the top widget (composed of the four smaller widgets):
QWidget *topWidget = new QWidget;
QHBoxLayout *topWidgetLayout = new QHBoxLayout(topWidget);
topWidgetLayout->addWidget(widget1);
topWidgetLayout->addWidget(widget2);
topWidgetLayout->addWidget(widget3);
topWidgetLayout->addWidget(widget4);
topWidgetLayout->addStretch(1); // add the stretch
topWidget->setFixedHeight(50);

// now put the bottom (centered) widget into its own QHBoxLayout
QHBoxLayout *hLayout = new QHBoxLayout;
hLayout->addStretch(1);
hLayout->addWidget(bottomWidget);
hLayout->addStretch(1);
bottomWidget->setFixedSize(QSize(50, 50));

// now use a QVBoxLayout to lay everything out
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(topWidget);
mainLayout->addStretch(1);
mainLayout->addLayout(hLayout);
mainLayout->addStretch(1);
如果您真的想要有两个单独的布局——一个用于粉色框,另一个用于蓝色框——基本上是一样的,只是您要将蓝色框制作成自己的QVBoxLayout,然后使用:

mainLayout->addWidget(topWidget);
mainLayout->addLayout(bottomLayout);