控件坚持太大并且不会在 Qt Designer 中调整大小
我在 Qt Designer 中制作了一个“小部件”,其中包含十几个组织为水平和垂直布局的控件。
奇怪的是,当整个表单设置为 275 像素宽时,每个水平布局都希望有一些大尺寸,大约 400 像素宽。其中包含的按钮等对于表单来说太宽。
当我垂直或水平调整小部件表单的大小(有时关闭最大宽度)时,各种布局不会调整大小。手动设置宽度(或最小宽度或最大宽度)可能会影响控件的大小,但不会影响它们在布局中的间距。插入垫片是为了将一些控件保持在顶部,将另一些控件保持在底部,并在其之间留出灵活的空间,但根本不起作用。
我忽略了哪些(可能)明显的事情?
I made a "widget" in Qt Designer with about a dozen controls organized into horizontal and vertical 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我很好地理解你的意思,那么表单的内容不是“连接的”,即不调整大小并且不受表单大小的限制,对吧?
我认为您错过了设置“centralWidget 布局”。
尝试以下操作:
在 Qt Creator 中双击打开表单(我不经常使用 Qt Designer,但我认为这两种工具的编辑器布局几乎相同)。
转到右上角的窗口(有 2 列“对象类”的窗口),然后用鼠标右键单击根对象(例如,MainWindow)。
将会出现一个上下文菜单。单击“布局”(最后一个菜单项)并选择“垂直布局”或“水平布局”。
这些操作将在centralWidget 对象上创建布局。如果您在“对象类”窗口中选择“centralWidget”,则可以查看和查看在(右下)属性值窗口中更改布局属性;它们是列表中的最后一个属性。
更重要的是,在centralWidget中添加布局后,表单的内容应该沿着&调整大小。受表单大小的限制。
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 setting a "centralWidget layout".
Try the following:
Open your form by double-clicking it in Qt Creator (I don't use the Qt Designer frequently, but I think the editor layout is almost the same on both tools).
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".
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.
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.
如果您使用 .qss 模板,请务必在记事本中打开它来检查其设置。有时这些模板会有自定义比例设置。
If you are using a .qss template, make sure to check its settings as well by opening it in a Notepad. Sometimes those templates will have custom scale settings.