使用 Qt-Designer 自动扩展布局
我正在使用 Qt 设计器。
我想创建一个 QVBoxLayout
它将自动扩展以填充整个窗口。
QVBoxLayout
的布局保持固定。
如何通过设计器使QVBoxLayout
展开并填充整个窗口?
I'm using the Qt Designer.
I want to create a QVBoxLayout
which will automatically expand to fill the whole window.
The layout of the QVBoxLayout
remains fixed.
How can I cause the QVBoxLayout
to expand and fill the entire window through the designer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在 Qt Designer 中创建
QVBoxLayout
后,右键单击小部件/对话框/窗口的背景(不是QVBoxLayout
,而是父小部件)并选择 布局 ->从上下文菜单的底部在网格中布局。QVBoxLayout
现在应该拉伸以适合窗口,并在调整整个窗口大小时自动调整大小。After creating your
QVBoxLayout
in Qt Designer, right-click on the background of your widget/dialog/window (not theQVBoxLayout
, but the parent widget) and select Lay Out -> Lay Out in a Grid from the bottom of the context-menu. TheQVBoxLayout
should now stretch to fit the window and will resize automatically when the entire window is resized.根据文档,需要有一个顶级布局集。
您可以通过清除选择并右键单击表单本身并选择上下文菜单中可用的布局之一来设置之一。
According to the documentation, there needs to be a top level layout set.
You can set one by clearing the selection and right clicking on the form itself and choosing one of the layouts available in the context menu.
我试图找到一个“适合屏幕”的属性,但没有这样的属性。
但是将小部件的“maximumSize”设置为“某个大数字”(例如 2000 x 2000 )将自动使小部件适合父小部件空间。
I've tried to find a "fit to screen" property but there is no such.
But setting widget's "maximumSize" to a "some big number" ( like 2000 x 2000 ) will automatically fit the widget to the parent widget space.
添加至少包含一个小部件的布局后,选择您的窗口并单击 QtDesigner 的“更新”按钮。界面将以最优化的尺寸调整,您的布局将适合整个窗口。然后当调整窗口大小时,布局也会以同样的方式调整大小。
Once you have add your layout with at least one widget in it, select your window and click the "Update" button of QtDesigner. The interface will be resized at the most optimized size and your layout will fit the whole window. Then when resizing the window, the layout will be resized in the same way.
设置horizontalPolicy &将控件/小部件的 VerticalPolicy 设置为“首选”。
Set the horizontalPolicy & VerticalPolicy for the controls/widgets to "Preferred".