简体   繁体   English

删除qt小部件时删除空间

[英]Remove space on removing qt widget

I have a grid layout on top of which there are 4 group boxes. 我有一个网格布局,在其上方有4个分组框。 When I try to hide one of the QGroupBoxes using groupBox->hide() , the group box is not visible anymore. 当我尝试使用groupBox->hide() QGroupBoxes之一时,组合框不再可见。 But the space is retained in the layout (I am not using QSizePolicy to retain the space) 但是空间保留在布局中(我没有使用QSizePolicy保留空间)

How do I make sure that space is automatically used by the remaining widgets? 如何确保剩余的小部件自动使用空间?

在此处输入图片说明

In the picture, I have hidden 'Group 2'. 在图片中,我隐藏了“第2组”。 I want Group 3 to automatically fill up the space. 我希望第3组自动填充空间。 How do I do this? 我该怎么做呢?

In order for the layout to do what you want, its child widgets have to 'behave' correctly. 为了使布局能够执行您想要的操作,其子窗口小部件必须正确地“表现”。 Ie if one of your group boxes contains a vertical spacer, it might mess up your layout. 也就是说,如果您的一个分组框包含一个垂直间隔符,则可能会弄乱您的布局。

I found that setting a stylesheet to the toplevel widget helps with debugging layout issues: 我发现将样式表设置为顶层小部件有助于调试布局问题:

pWidget->setStyleSheet("border: 1px solid red;");

This will paint a red border around (some) widgets and clarifies who uses which space. 这将在(一些)小部件周围绘制一个红色边框,并阐明谁在使用哪个空间。

You could try to add a vertical spacer below the third group box to "push" them all upwards. 您可以尝试在第三个组框下方添加垂直间隔器,以将它们全部“向上推”。 If one of the group boxes is then set to invisible, the others should get pushed up and the space between group box 1 and 3 should disappear. 如果然后将其中一个组框设置为不可见,则其他组框应向上推,并且组框1和3之间的空间应消失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM