问题描述
我想要一个小的 QFormLayout
来填充它的父小部件.
I want to have a small QFormLayout
that grows to fill its parent widget.
我使用 Qt Designer 中的 QWidget
模板创建了一个新的 .ui 文件.我在那个窗口"里面放了一个 QFormLayout
,然后在那个 QFormLayout
里面放了一些控件.
I created a new .ui file using the QWidget
template in Qt Designer. I put a QFormLayout
inside that 'window', then put some controls inside that QFormLayout
.
这一切都运行得相当好,但 QFormLayout
始终保持我在 Qt 设计器中设置的大小.我希望 QFormLayout
填充它的父小部件并用它增长/缩小.
This all works reasonably well, but the QFormLayout
always stays at the size I set in Qt Designer. I would like the QFormLayout
to fill its parent widget and grow/shrink with it.
我怎样才能做到这一点?
How can I accomplish that?
推荐答案
在 Designer 中,激活 centralWidget 并分配布局,例如水平或垂直布局.然后你的 QFormLayout 会自动调整大小.
In Designer, activate the centralWidget and assign a layout, e.g. horizontal or vertical layout.Then your QFormLayout will automatically resize.
始终确保所有小部件都有布局!否则,自动调整大小将与该小部件中断!
Always make sure, that all widgets have a layout! Otherwise, automatic resizing will break with that widget!
这篇关于如何使 Qt Widget 随着窗口大小而增长?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!