2014-08-29 74 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