Resize QDialog at a runtime

2020-02-26 11:04发布

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. enter image description here
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 enter image description here
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. enter image description here
Can anybody help me?

1条回答
仙女界的扛把子
2楼-- · 2020-02-26 11:37

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.

查看更多
登录 后发表回答