QBoxLayout class lines up child widgets horizontally or vertically. 更多...
头: | #include <QBoxLayout> |
qmake: | QT += widgets |
继承: | QLayout |
继承者: |
enum | Direction { LeftToRight, RightToLeft, TopToBottom, BottomToTop } |
QBoxLayout (Direction dir , QWidget * parent = Q_NULLPTR) | |
~QBoxLayout () | |
void | addLayout (QLayout * layout , int stretch = 0) |
void | addSpacerItem (QSpacerItem * spacerItem ) |
void | addSpacing (int size ) |
void | addStretch (int stretch = 0) |
void | addStrut (int size ) |
void | addWidget (QWidget * widget , int stretch = 0, Qt::Alignment alignment = Qt::Alignment()) |
Direction | direction () const |
void | insertItem (int index , QLayoutItem * item ) |
void | insertLayout (int index , QLayout * layout , int stretch = 0) |
void | insertSpacerItem (int index , QSpacerItem * spacerItem ) |
void | insertSpacing (int index , int size ) |
void | insertStretch (int index , int stretch = 0) |
void | insertWidget (int index , QWidget * widget , int stretch = 0, Qt::Alignment alignment = Qt::Alignment()) |
void | setDirection (Direction direction ) |
void | setSpacing (int spacing ) |
void | setStretch (int index , int stretch ) |
bool | setStretchFactor (QWidget * widget , int stretch ) |
bool | setStretchFactor (QLayout * layout , int stretch ) |
int | spacing () const |
int | stretch (int index ) const |
virtual void | addItem (QLayoutItem * item ) |
virtual int | count () const |
virtual Qt::Orientations | expandingDirections () const |
virtual bool | hasHeightForWidth () const |
virtual int | heightForWidth (int w ) const |
virtual void | invalidate () |
virtual QLayoutItem * | itemAt (int index ) const |
virtual QSize | maximumSize () const |
virtual int | minimumHeightForWidth (int w ) const |
virtual QSize | minimumSize () const |
virtual void | setGeometry (const QRect & r ) |
virtual QSize | sizeHint () const |
virtual QLayoutItem * | takeAt (int index ) |
QBoxLayout class lines up child widgets horizontally or vertically.
QBoxLayout takes the space it gets (from its parent layout or from the parentWidget ()),将其分成行框,并使每个被管理的 Widget 填充一个框。
若 QBoxLayout 's orientation is Qt::Horizontal 框按合适尺寸排成一行。每个 Widget (或其它框) 将至少获得其最小尺寸和最多获得其最大尺寸。任何多余空间根据拉伸因子共享 (下文有关这更多)。
若 QBoxLayout 's orientation is Qt::Vertical ,框将再次采用合适尺寸排成一列。
The easiest way to create a QBoxLayout is to use one of the convenience classes, e.g. QHBoxLayout (for Qt::Horizontal 框) 或 QVBoxLayout (for Qt::Vertical boxes). You can also use the QBoxLayout constructor directly, specifying its direction as LeftToRight , RightToLeft , TopToBottom ,或 BottomToTop .
若 QBoxLayout is not the top-level layout (i.e. it is not managing all of the widget's area and children), you must add it to its parent layout before you can do anything with it. The normal way to add a layout is by calling parentLayout-> addLayout ().
Once you have done this, you can add boxes to the QBoxLayout using one of four functions:
使用 insertWidget (), insertSpacing (), insertStretch () 或 insertLayout () 以在布局中指定位置插入框。
QBoxLayout also includes two margin widths:
边距默认由样式提供。大多数 Qt 样式指定的默认边距对于 Widget 为 9,对于窗口为 11。间距默认与顶层布局边距宽度相同,或与父布局相同。
要从布局移除 Widget,调用 removeWidget ()。调用 QWidget::hide () 在 Widget 还会从布局高效移除小部件,直到 QWidget::show () 被调用。
几乎总是想要使用 QVBoxLayout and QHBoxLayout 而不是 QBoxLayout because of their convenient constructors.
另请参阅 QGridLayout , QStackedLayout ,和 布局管理 .
此类型用于确定框布局的方向。
常量 | 值 | 描述 |
---|---|---|
QBoxLayout::LeftToRight
|
0
|
水平从左到右。 |
QBoxLayout::RightToLeft
|
1
|
水平从右到左。 |
QBoxLayout::TopToBottom
|
2
|
垂直从上到下。 |
QBoxLayout::BottomToTop
|
3
|
垂直从下到上。 |
构造新的 QBoxLayout with direction dir 和父级小部件 parent .
另请参阅 direction ().
销毁此框布局。
布局的 Widget 不被销毁。
[virtual]
void
QBoxLayout::
addItem
(
QLayoutItem
*
item
)
重实现自 QLayout::addItem ().
添加 layout 到方框末尾,采用连续拉伸因子 stretch .
另请参阅 insertLayout (), addItem (),和 addWidget ().
添加 spacerItem 到此方框布局的末尾。
该函数在 Qt 4.4 引入。
另请参阅 addSpacing () 和 addStretch ().
添加不可拉伸空间 ( QSpacerItem ) 采用尺寸 size 到此方框布局的末尾。 QBoxLayout 提供默认边距和间距。此函数添加额外空间。
另请参阅 insertSpacing (), addItem (),和 QSpacerItem .
添加可拉伸空间 ( QSpacerItem ) 采用 0 最小尺寸和拉伸因子 stretch 到此方框布局的末尾。
另请参阅 insertStretch (), addItem (),和 QSpacerItem .
限制框的垂直尺度 (如:高度若框是 LeftToRight ) 到最小 size 。其它约束可能递增限制。
另请参阅 addItem ().
添加 widget 到此框布局的末尾,采用拉伸因子 stretch 和对齐 alignment .
拉伸因子仅应用于 direction 的 QBoxLayout ,且相对于其它方框和 Widget 在此 QBoxLayout 。具有更高拉伸因子的 Widget 和方框增长更多。
若拉伸因子为 0 且什么都没有除非 QBoxLayout 拥有大于 0 的拉伸因子,空间分布将根据 QWidget :sizePolicy() 对于涉及的每个 Widget。
对齐方式的指定通过 alignment 。默认对齐为 0,意味着 Widget 填充整个单元格。
另请参阅 insertWidget (), addItem (), addLayout (), addStretch (), addSpacing (),和 addStrut ().
[virtual]
int
QBoxLayout::
count
() const
重实现自 QLayout::count ().
返回框的方向。 addWidget () 和 addSpacing () 工作于此方向;拉伸将在此方向延伸。
另请参阅 setDirection (), QBoxLayout::Direction , addWidget (),和 addSpacing ().
[virtual]
Qt::Orientations
QBoxLayout::
expandingDirections
() const
重实现自 QLayoutItem::expandingDirections ().
[virtual]
bool
QBoxLayout::
hasHeightForWidth
() const
重实现自 QLayoutItem::hasHeightForWidth ().
[virtual]
int
QBoxLayout::
heightForWidth
(
int
w
) const
重实现自 QLayoutItem::heightForWidth ().
插入 item 到此框布局在位置 index 。若 index 为负,项被添加在末尾。
另请参阅 addItem (), insertWidget (), insertLayout (), insertStretch (),和 insertSpacing ().
插入 layout 在位置 index ,采用拉伸因子 stretch 。若 index 为负,布局被添加在末尾。
layout 变为框布局的子级。
另请参阅 addLayout () 和 insertItem ().
插入 spacerItem 在位置 index ,采用 0 最小尺寸和拉伸因子。若 index 为负,空间被添加在末尾。
该函数在 Qt 4.4 引入。
另请参阅 addSpacerItem (), insertStretch (),和 insertSpacing ().
插入不可拉伸空间 ( QSpacerItem ) 在位置 index ,采用尺寸 size 。若 index 为负,空间被添加在末尾。
框布局具有默认的边距和间距。此函数添加额外空间。
另请参阅 addSpacing (), insertItem (),和 QSpacerItem .
插入可拉伸空间 ( QSpacerItem ) 在位置 index ,采用 0 最小尺寸和拉伸因子 stretch 。若 index 为负,空间被添加在末尾。
另请参阅 addStretch (), insertItem (),和 QSpacerItem .
插入 widget 在位置 index ,采用拉伸因子 stretch 和对齐 alignment 。若 index 为负,Widget 被添加到末尾。
拉伸因子仅应用于 direction 的 QBoxLayout ,且相对于其它方框和 Widget 在此 QBoxLayout 。具有更高拉伸因子的 Widget 和方框增长更多。
若拉伸因子为 0 且什么都没有除非 QBoxLayout 拥有大于 0 的拉伸因子,空间分布将根据 QWidget :sizePolicy() 对于涉及的每个 Widget。
对齐方式的指定通过 alignment 。默认对齐为 0,意味着 Widget 填充整个单元格。
另请参阅 addWidget () 和 insertItem ().
[virtual]
void
QBoxLayout::
invalidate
()
重实现自 QLayoutItem::invalidate ().
重置缓存信息。
[virtual]
QLayoutItem
*QBoxLayout::
itemAt
(
int
index
) const
重实现自 QLayout::itemAt ().
[virtual]
QSize
QBoxLayout::
maximumSize
() const
重实现自 QLayoutItem::maximumSize ().
[virtual]
int
QBoxLayout::
minimumHeightForWidth
(
int
w
) const
重实现自 QLayoutItem::minimumHeightForWidth ().
[virtual]
QSize
QBoxLayout::
minimumSize
() const
重实现自 QLayoutItem::minimumSize ().
将此布局的方向设为 direction .
另请参阅 direction ().
[virtual]
void
QBoxLayout::
setGeometry
(const
QRect
&
r
)
重实现自 QLayoutItem::setGeometry ().
重实现 QLayout::setSpacing ()。把间距特性设为 spacing .
另请参阅 QLayout::setSpacing () 和 spacing ().
设置拉伸因子在位置 index 。到 stretch .
该函数在 Qt 4.5 引入。
另请参阅 stretch ().
设置拉伸因子为
widget
to
stretch
和返回 true 若
widget
在此布局中被找到 (不包括子级布局);否则返回
false
.
另请参阅 setAlignment ().
这是重载函数。
设置拉伸因子为布局
layout
to
stretch
并返回
true
if
layout
在此布局中被找到 (不包括子级布局);否则返回
false
.
[virtual]
QSize
QBoxLayout::
sizeHint
() const
重实现自 QLayoutItem::sizeHint ().
重实现 QLayout::spacing ()。若间距特性有效,返回该值。否则,计算并返回间距特性的值。由于 Widget 布局间距从属样式,因此,若父级是 Widget,它会查询样式为布局 (水平或垂直) 间距。否则,若父级是布局,它会查询父级布局为 spacing()。
另请参阅 QLayout::spacing () 和 setSpacing ().
返回拉伸因子在位置 index .
该函数在 Qt 4.5 引入。
另请参阅 setStretch ().
[virtual]
QLayoutItem
*QBoxLayout::
takeAt
(
int
index
)
重实现自 QLayout::takeAt ().