当内容部分被隐藏时,在运行时调整包含QVBoxLayout的QWidget的大小 [英] Resize a QWidget containing a QVBoxLayout in runtime when contents are partially Hidden

查看:472
本文介绍了当内容部分被隐藏时,在运行时调整包含QVBoxLayout的QWidget的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此应用程序中,生成一个HBoxLayout列表,并将其放入VBoxLayout中,以形成动态填充的命令列表。每个子列表上方都有一个按钮,可以隐藏下面的控件。问题:当子列表被隐藏时,包含最广泛的VBoxLayout的窗口小部件的大小不会改变! VBoxLayout然后伸展补偿。我想要容器小部件缩小,当它包含较少的项目!
它看起来像这样:



问题是,当我在一个PushButtons下隐藏列表时,包含的窗口小部件不会缩小!当有不太明显的项目时,VBoxLayout就会扩展:(



这是一张我如何看到我的小GUI的图片。



以下是更广泛的布局设置中的一些代码:

  scrollArea = new QScrollArea(this); 
scrollAreaLayoutWidget = new QWidget(scrollArea);
scrollAreaLayout = new QVBoxLayout(scrollAreaLayoutWidget);
// scrollAreaLayout填充了您在滚动区域内看到的所有内容...
scrollArea-> setWidget(scrollAreaLayoutWidget);

我已经尝试更改容器小部件的QSizePolicy(蓝框)我发现了几十个调整大小的问题,但是我以某种方式没有发现一个答案,有没有一个魔术自动调整大小的设置,我错过了
让我知道如果这是痛苦的模糊或不完整的。
欢迎任何意见!

解决方案

结果我所要做的就是创建一个自定义SLOT,当b隐藏Ui的一部分的utton被单击并隐藏该功能中的相关小部件。在同一个函数中,我调用了 [containerWidget] - > adjustSize(); ,它完全正是我正在寻找的。

In this application, a list of HBoxLayouts is generated and put into a VBoxLayout in order to form a dynamically filled list of commands. There is a button above each sub-list which has the capability to hide the controls below it. The problem: when a sub-list is hidden, the widget which contains the broadest VBoxLayout does not change in size! The VBoxLayout then stretches to compensate. I want the container widget to shrink when it contains fewer items! It looks like this:

The problem is, when I hide a list under one of the PushButtons, the containing widget won't shrink! the VBoxLayout just expands when there are less visible items :(

Here is a picture of how I see my little GUI.

Here is some code from the broader layout setup:

scrollArea = new QScrollArea(this);
scrollAreaLayoutWidget = new QWidget(scrollArea);
scrollAreaLayout = new QVBoxLayout(scrollAreaLayoutWidget);
//scrollAreaLayout is filled with all the stuff you see inside the scroll area...
scrollArea->setWidget(scrollAreaLayoutWidget);

I have tried changing the QSizePolicy of the container widget (blue box) in a number of ways. I've found dozens of resizing questions but I have somehow not discovered an answer. Is there a magic auto-resize setting that I'm missing? Let me know if this is painfully vague or incomplete. Any comment is welcome!

解决方案

Turns out all I had to do was create a custom SLOT for when the button that hides part of the Ui is clicked and hide the relevant widget within that function. In the same function, I called [containerWidget]->adjustSize(); and it did exactly what I was looking for.

这篇关于当内容部分被隐藏时,在运行时调整包含QVBoxLayout的QWidget的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆