在运行时调整 QDialog 的大小 [英] Resize QDialog at a runtime

查看:72
本文介绍了在运行时调整 QDialog 的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 QDialog 子类,其中包含我的应用程序的一些选项.一些选项是核心的,另一些是高级的,所以我决定把它们放在单独的可检查 QGroupBox 中.
当用户选中高级选项框时,我希望我的对话框垂直缩小,但我找不到正确执行此操作的方法 - 对话框大小保持完全相同
我将对话框的大小策略设置为 Expanding,尝试调用 adjustSize() 并尝试调用 resize() 方法 - 没有任何帮助.我无法以编程方式将对话框的大小调整为比当前大小更小(它只能变大).同时,可以手动调整其大小.
有人可以帮我吗?

I have a QDialog subclass containing some options of my application. Some of the options are core, the other are advanced, so I decided to put them into separeted checkable QGroupBox.
I want my dialog to shrink verticaly when the user checked off advanced options box, but I can't find the way to do it properly - the dialog size stays exactle the same
I set dialog's size policy to Expanding, tried to call adjustSize() and tried to call resize() method - nothing helps. I can't resize programmaticaly dialog to be smaller then it's current size (it only can become larger). At the same time, it is possible to resize it manualy.
Can anybody help me?

推荐答案

如果不需要手动调整大小,可以添加

If you don't need manual resize, you can add

layout()->setSizeConstraint(QLayout::SetFixedSize);

到对话框构造函数,然后布局负责在显示或隐藏小部件时自动调整大小.

to the dialog constructor, then the layout takes over the responsibility to automatically resize when widgets are shown or hidden.

这篇关于在运行时调整 QDialog 的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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