QtDesigner 中的控件坚持太大,并且不会调整大小

问题描述:

我在 Qt Designer 中制作了一个小部件",其中大约有十几个控件被组织成 horiz.和垂直.布局.奇怪的是,当整个表单设置为 275px 宽时,每个水平布局都想要一些大尺寸,大约 400 px 宽.包含在其中的按钮等对于表单来说太宽了.当我垂直或水平调整小部件表单的大小(有时关闭最大宽度)时,各种布局不会调整大小.手动设置宽度(或最小宽度或最大宽度)可能会影响控件的大小,但不会影响它们在布局中的间距.插入垫片以将一些控件保留在顶部,将其他一些控件保留在底部,并在两者之间留出灵活的空间,但根本不起作用.

I made a "widget" in Qt Designer with about a dozen controls organized into horiz. and vert. layouts. Oddly, every horizontal layout wants to be some large size, about 400 px wide, when the whole form is set to be 275px wide. Buttons etc contained within are too wide for the form. When I resize the widget form vertically or horizontally (sometimes with the max width turned off) the various layouts won't resize. Manually setting widths (or min widths, or max widths) may affect the sizes of the controls, but not their spacing within the layout. Spacers inserted to keep some controls at the top and some others at the bottom with a flexible space between, just don't work at all.

我忽略了什么(可能)显而易见的事情?

What (probably) obvious thing am I overlooking?

(我通常不是应用程序或 GUI 程序员,在这方面完全是个原始人.)

(I am normally not an applications or GUI programmer, a total caveman at this.)

不要怪自己,我觉得 Qt 的 Layout 逻辑在你开始处理的时候有点混乱.如果我理解你的意思,表格的内容没有连接",即不调整大小,不受表格大小的限制,对吗?我认为您错过了设置centralWidget 布局".请尝试以下操作:

Don't blame yourself, I think Qt's Layout logic is a bit confusing when you start to deal with. If I understood well what you are saying, the contents of the form are not "connected", i.e. not resizing and not restricted by the form size, right? I think you have missed to set a "centralWidget layout". Try the following:

  1. 在 QtCreator 中双击打开表单(我不经常使用 QtDesigner,但我认为这两种工具的编辑器布局几乎相同).

  1. Open your form by double clicking it in QtCreator (I don't use the QtDesigner frequently but I think the editor layout is almost the same on both tools).

转到右上角的窗口(该窗口有 2 列Object-Class"),然后用鼠标右键单击根对象(例如 MainWindow).

Go to the top-right window (the one having 2 columns "Object-Class") and Right-Click with your mouse at the root object (e.g. MainWindow).

将出现一个上下文菜单.单击布局"(最后一个菜单项)并选择垂直布局"或水平布局"

A context menu will appear. Click on "Lay out" (last menu item) and select "Layout Vertically" or "Layout Horizontally"

这些操作将在 centralWidget 对象上创建布局.如果您在Object-Class"窗口中选择centralWidget",您就可以查看 &更改(右下)Property-Value 窗口中的布局属性;它们是列表中的最后一个属性.

These actions will create a layout on the centralWidget object. If you select the "centralWidget" in the "Object-Class" window you can then view & change the layout properties in the (bottom-right) Property-Value window; they are the last properties in list.

更重要的是,在你的 centralWidget 中添加布局之后,你的表单内容应该随着 & 调整大小.受表单大小的限制.

More important, after you add a layout in your centralWidget, the contents of your form should be resizing along & limited by your form's size.

我希望这会有所帮助.