2014-08-29 76 views
0

非常感谢您建议如何创建由四个布局组成的Qt UI,并且具有以下属性。使用布局创建自动缩放Qt UI

  1. 在UI的高度的任何增加是由布局吸收,如下所示 enter image description here

  2. 在UI的高度的任何进一步减少由特定布局中的内容吸收,例如两个大按钮,如下图所示 enter image description here

回答

1

我准备了简单的代码什么适合您的问题,请看看:https://github.com/troyane/StackOverflow-pro/tree/master/creating-auto-scaling-qt-ui-using-layouts

抢码,并看看下一时刻(您可以在QtCreator打开mainwindow.ui):

  • centralWidget旁边layoutStretch PARAM:1,2,1,1 - 这意味着,我们就拥有了所有项目中一个相关放置在这个垂直布局中。
  • TextLabel两者SmallButton S有Fixed VerticalPolicy
  • 两个BigButton S有Minimum垂直政策和设置的minimumSize的高度为100 UPD:maximumSize - >height参数250像素。所以,保证BigButtons的高度不会超过250px。

看看another answer,那里你可以找到很多文学阅读有关布局

+0

谢谢。不幸的是,我不希望大按钮超出一定范围。有没有办法将大按钮的高度限制在最大值? – Olumide 2014-09-01 09:48:02

+0

当然,请参阅回购中更新的答案和更新的代码。 – troyane 2014-09-01 10:07:16

0

您可以将两个垂直间隔在每个布局。每个人都应该在最顶端,另一个被放置在底部:

enter image description here

5

1#在QWidget的新UI形式基地:文件 - >新建文件或项目 - > Qt的 - > Qt设计表单类 - >选择窗口小部件的表单模板,下一步,下一步,选择项目并完成

2#从左边栏中添加垂直布局

enter image description here

3#之后点击右键某处UI形式,其中不菊ST补充布局, “铺陈” - >

enter image description here

4#你可以调整右键菜单上的布局保证金 “在网格中铺陈”(我总是设置5分)

5 #加入四横布局

enter image description here

6#添加按钮和文本,哪些是你需要

enter image description here

7#添加水平布局之间的垂直间隔

enter image description here

8#最终结果:

enter image description here enter image description here enter image description here

+0

Upvote for tutorial value。 – Olumide 2014-09-01 10:20:46