【发布时间】:2018-08-07 20:50:28
【问题描述】:
我在运行时创建了一个 VerticalLayout 并在其上添加了几个复选框。但是复选框在表单顶部有巨大的空白。我无法缩小它们之间的差距并修剪顶部的额外空白。
下面是ui和cpp文件的源代码:
HideChartConfig.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>HideChartConfig</class>
<widget class="QDialog" name="HideChartConfig">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>559</height>
</rect>
</property>
<property name="windowTitle">
<string></string>
</property>
<widget class="QScrollArea" name="scrollArea">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>381</width>
<height>471</height>
</rect>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>379</width>
<height>469</height>
</rect>
</property>
</widget>
</widget>
<widget class="QPushButton" name="okButton">
<property name="geometry">
<rect>
<x>310</x>
<y>510</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>OK</string>
</property>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
HideChartConfig 的构造函数内部:
this->setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
ui->setupUi(this);
QPalette pal = ui->scrollArea->palette();
pal.setColor(QPalette::Background, Qt::white);
ui->scrollArea->setPalette(pal);
QWidget* container = new QWidget();
m_ContainerLayout = new QVBoxLayout();
container->setLayout(m_ContainerLayout);
ui->scrollArea->setWidget(container);
m_ContainerLayout->addStretch();
for (int i = 0; i < 3; i++)
{
QCheckBox *checkbox = new QCheckBox("Hello");
m_ContainerLayout->addWidget(checkbox, 0, Qt::AlignTop);
}
m_ContainerLayout->addStretch();
m_ContainerLayout->setSpacing(0);
另附截图供参考:
我希望复选框出现在表单顶部并修剪顶部多余的空白。
感谢任何帮助。提前致谢!
【问题讨论】:
-
你可以展示你想要得到的图像。
-
@eyllanesc :我希望复选框出现在表单顶部并修剪顶部多余的空白区域。