有效的 Qt 布局管理
看起来 Qt 中的布局非常强大和灵活,但有时不是很直观。有时我必须摆弄以获得所需的小部件布局。也许我的方法不对?
看看这个表单:
- a 所做的布局是表单的布局 - a 无法看到其边缘,我也看不到在 Qt Designer 中找到为此的任何设置。
- 标签及其小部件之间的空间(我更喜欢将其放置在小部件上方,而不是它们的左侧)太大。我可以为它们设置最大尺寸,或者我可以为每个标签及其小部件制作子布局 - 但这是正确的方法吗?
- 看起来这个布局有几列。我可以从布局中添加/删除列/行而不破坏它并再次创建它吗?我该如何以最好的方式做到这一点?最左边的列比第二列更窄 - 从最左边的列设置一个小部件的最小宽度没有帮助。
我一直在互联网上寻找有关如何在 Qt Designer 中制作良好布局的文章。你有链接吗? 您能分享一下您使用 Qt 布局的技术吗?
Looks like layouts in Qt are quite powerful and flexible, but sometimes not very intuitive. I must fiddle sometimes to get a desired widgets layout. Maybe i have wrong approach?
Look at this form:
- The layout a made is form's layout - a cannot see its edges and i could not find any settings in Qt Designer for this.
- The space between labels and their widgets (which i prefer to place above the widgets, not on the left side of them) is too big. I can set
maximum
size for them or i can make sublayouts for each label and its widget - but is this the way to go? - Looks like this layout has several columns. Can i add/delete a column/row from the layout without breaking it and making it again? How to i do this the best way? The left most column is narrower the the second column - setting the minimum width of one of the widgets from the left most column didn't help.
I've been looking in Internet for articles on how to make good layouts in Qt Designer. Do you have any links?
Would you please share your techniques on working with Qt layouts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要获取布局属性,请选择包含布局的小部件(例如在右上对象资源管理器中)并向下滚动属性(右下)列表。在列表的末尾,您会找到它。
空间由属性layoutHorizontal|VerticalSpacing设置。您还可以通过样式表为布局中的每个小部件设置边距|填充。
布局的列数和行数会自动计算。如果该小部件位于列|行中的最后一个,则从表单中添加或删除小部件将添加或删除布局中的列或行。如果您想在布局中重新分配小部件,您可以使用行|列拉伸(布局属性)来放大或缩小一些列|行,或者在布局中添加间隔。享受 =)
PS 对于构建复杂的表单,我建议使用 QGridLayout。它功能强大,可以构建出色的小部件和表单。
To get layout properties select widget, which contain layout, (in right-top object explorer, for example) and scroll down properties (right-bottom) list. At the end of the list you'll find it.
Space are set up by properties layoutHorizontal|VerticalSpacing. Also you can set margin|padding for each widget in layout via stylesheets.
Layout's columns and rows count calculate automatically. Adding or removing widget from form will add or remove column or row in layout if that widget was last in column|row. If you want reallocate widgets in layout you can play with row|column stretch (layout properties) to do some column|row bigger or smaller or add spacers to layout. Enjoy =)
P.S. For build complex form I recommend to use QGridLayout. It is powerful and allow to construct splendid widgets and forms.