【转】QGridLayout 详解
轉自:https://blog.csdn.net/u013928315/article/details/78123573
一、QGridLayout屬性介紹
?
1、QGridlayout以方格的形式管理窗口部件,先看QGridLayout的屬性,如下圖
2、各個參數的介紹
layoutLeftMargin ...至layoutBottomMargin在ui_MainWindow.h中自動生成的代碼是:
gridLayout->setContentsMargins(20, 10, 10, 10);
學過CSS都知道,這是設置一個元素所有外邊距的寬度,或者設置各邊上外邊距的寬度
On most platforms, the margin is 11 pixels in all directions.
?
HorizontalSpacing...至VerticalSpacing在ui_MainWindow.h中自動生成的代碼是:
?
? ? ? ? gridLayout->setHorizontalSpacing(6);
? ? ? ? gridLayout->setVerticalSpacing(6);
? ? ? ? 這是設置兩個控件之間的水平和豎直距離
?
LayoutRowStretch在ui_MainWindow.h中自動生成的代碼是:
?
gridLayout->setRowStretch(0, 1);
? ? ? ? gridLayout->setRowStretch(1, 1);
? ? ? ? gridLayout->setRowStretch(2, 1);
表示在第0行、第1行、第2行 在豎直方向的空間比例分配,大家稍微改一下參數就能看出來效果
LayoutColumnStretch在ui_MainWindow.h中自動生成的代碼是:? ? ??
gridLayout->setColumnStretch(1, 1);
?
表示設置第0列、第1列兩者在水平方向的空間比例分配。
?
?
LayoutRowMinimumHeight在ui_MainWindow.h中自動生成的代碼是:
?
? ? ? ? gridLayout->setRowMinimumHeight(0, 1);
? ? ? ? gridLayout->setRowMinimumHeight(1, 2);
? ? ? ? gridLayout->setRowMinimumHeight(2, 3);
表示在第0行、第1行、第2行的最小高度是1pixels,2pixels,3pixels
LayoutColumnMinimumWidth在ui_MainWindow.h中自動生成的代碼是:
?
? gridLayout->setColumnMinimumWidth(0, 4);
? ? ? ? gridLayout->setColumnMinimumWidth(1, 5);
表示設置第0列、第1列的最小寬度是4pixels、5pixels
?
?
LayoutSizeConstraint在ui_MainWindow.h中自動生成的代碼是:
gridLayout->setSizeConstraint(QLayout::SetDefaultConstraint);
?
This property holds the resize mode of the layout.看下表
?
?
?
?
enum QLayout::SizeConstraint
The possible values are:
Constant Value Description
| QLayout::SetDefaultConstraint | 0 | The main widget's minimum size is set to?minimumSize(), unless the widget already has a minimum size. |
| QLayout::SetFixedSize | 3 | The main widget's size is set to?sizeHint(); it cannot be resized at all. |
| QLayout::SetMinimumSize | 2 | The main widget's minimum size is set to?minimumSize(); it cannot be smaller. |
| QLayout::SetMaximumSize | 4 | The main widget's maximum size is set to?maximumSize(); it cannot be larger. |
| QLayout::SetMinAndMaxSize | 5 | The main widget's minimum size is set to?minimumSize() and its maximum size is set tomaximumSize(). |
| QLayout::SetNoConstraint | 1 | The widget is not constrained. ? ? |
?
QFormLayout屬性介紹
1、QFormLayout類管理輸入型控件和它的label組成的那些form表格,包括它的界面參數如下圖
?
?
2、界面中對應的代碼如下表,
?
?
Cpp代碼???
?
3、其中值得一說的是:LayoutFieldGrowthPolicy屬性
?
?
enum QFormLayout::FieldGrowthPolicy
This enum specifies the different policies that can be used to control the way in which the form's fields grow.
Constant Value Description
| QFormLayout::FieldsStayAtSizeHint | 0 | The fields never grow beyond their?effective size hint. This is the default forQMacStyle. |
| QFormLayout::ExpandingFieldsGrow | 1 | Fields with an horizontal?size policy?of?Expanding?or?MinimumExpanding?will grow to fill the available space. The other fields will not grow beyond their effective size hint. This is the default policy for Plastique. |
| QFormLayout::AllNonFixedFieldsGrow | 2 | All fields with a size policy that allows them to grow will grow to fill the available space. This is the default policy for most styles. |
?
?
?
4、還有一個屬性值得說:LayoutRowWrapPolicy
?
This property holds the way in which the form's rows wrap.
//這個屬性設置了表格如何排版各個元素
If you want to display each label above its associated field (instead of next to it), set this property to WrapAllRows.
//如果你想把每個標簽放在相關字段的上方,而不是和它相鄰,就設置這個屬性值為WrapAllRows。
?
?
enum QFormLayout::RowWrapPolicy
This enum specifies the different policies that can be used to control the way in which the form's rows wrap.
Constant Value Description
| QFormLayout::DontWrapRows | 0 | Fields are always laid out next to their label. This is the default policy for all styles except Qt Extended styles and?QS60Style. |
| QFormLayout::WrapLongRows | 1 | Labels are given enough horizontal space to fit the widest label, and the rest of the space is given to the fields. If the minimum size of a field pair is wider than the available space, the field is wrapped to the next line. This is the default policy for Qt Extended styles and andQS60Style. |
| QFormLayout::WrapAllRows | 2 | Fields are always laid out below their label. |
總結
以上是生活随笔為你收集整理的【转】QGridLayout 详解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 前端和后端的英文_计算机专业的本科生在前
- 下一篇: 超10万人联名写信抗议丰田!“不听话”就