QLayout的属性介绍
主要包括QBoxLayout、和QGridLayout以及QFormLayout等的参数类似。
?
我主要说明一下QGridLayout在QtDesigner中它的属性的意义,以及QFormLayout的部分属性
?
?
?
一、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.看下表
?
?
?
?
032451
?
2、界面中对应的代码如下表,
?
?
012012Fields are always laid out below their label.?
?