
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQBoxLayout class lines up child widgets horizontally or vertically.More...
| Header: | #include <QBoxLayout> |
| Inherits: | QLayout |
| Inherited By: |
| enum | Direction { LeftToRight, RightToLeft, TopToBottom, BottomToTop } |
| QBoxLayout(Direction dir, QWidget * parent = 0) | |
| ~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 = 0) |
| Direction | direction() const |
| 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 = 0) |
| 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) |
| void | insertItem(int index, QLayoutItem * item) |
TheQBoxLayout class lines up child widgets horizontally or vertically.
QBoxLayout takes the space it gets (from its parent layout or from theparentWidget()), divides it up into a row of boxes, and makes each managed widget fill one box.

If theQBoxLayout's orientation isQt::Horizontal the boxes are placed in a row, with suitable sizes. Each widget (or other box) will get at least its minimum size and at most its maximum size. Any excess space is shared according to the stretch factors (more about that below).

If theQBoxLayout's orientation isQt::Vertical, the boxes are placed in a column, again with suitable sizes.
The easiest way to create aQBoxLayout is to use one of the convenience classes, e.g.QHBoxLayout (forQt::Horizontal boxes) orQVBoxLayout (forQt::Vertical boxes). You can also use theQBoxLayout constructor directly, specifying its direction asLeftToRight,RightToLeft,TopToBottom, orBottomToTop.
If theQBoxLayout 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 theQBoxLayout using one of four functions:
UseinsertWidget(),insertSpacing(),insertStretch() orinsertLayout() to insert a box at a specified position in the layout.
QBoxLayout also includes two margin widths:
The margin default is provided by the style. The default margin most Qt styles specify is 9 for child widgets and 11 for windows. The spacing defaults to the same as the margin width for a top-level layout, or to the same as the parent layout.
To remove a widget from a layout, callremoveWidget(). CallingQWidget::hide() on a widget also effectively removes the widget from the layout untilQWidget::show() is called.
You will almost always want to useQVBoxLayout andQHBoxLayout rather thanQBoxLayout because of their convenient constructors.
See alsoQGridLayout,QStackedLayout, andLayout Management.
This type is used to determine the direction of a box layout.
| Constant | Value | Description |
|---|---|---|
QBoxLayout::LeftToRight | 0 | Horizontal from left to right. |
QBoxLayout::RightToLeft | 1 | Horizontal from right to left. |
QBoxLayout::TopToBottom | 2 | Vertical from top to bottom. |
QBoxLayout::BottomToTop | 3 | Vertical from bottom to top. |
Constructs a newQBoxLayout with directiondir and parent widgetparent.
See alsodirection().
Destroys this box layout.
The layout's widgets aren't destroyed.
[virtual]void QBoxLayout::addItem(QLayoutItem * item)Reimplemented fromQLayout::addItem().
Addslayout to the end of the box, with serial stretch factorstretch.
See alsoinsertLayout(),addItem(), andaddWidget().
AddsspacerItem to the end of this box layout.
This function was introduced in Qt 4.4.
See alsoaddSpacing() andaddStretch().
Adds a non-stretchable space (aQSpacerItem) with sizesize to the end of this box layout.QBoxLayout provides default margin and spacing. This function adds additional space.
See alsoinsertSpacing(),addItem(), andQSpacerItem.
Adds a stretchable space (aQSpacerItem) with zero minimum size and stretch factorstretch to the end of this box layout.
See alsoinsertStretch(),addItem(), andQSpacerItem.
Limits the perpendicular dimension of the box (e.g. height if the box isLeftToRight) to a minimum ofsize. Other constraints may increase the limit.
See alsoaddItem().
Addswidget to the end of this box layout, with a stretch factor ofstretch and alignmentalignment.
The stretch factor applies only in thedirection of theQBoxLayout, and is relative to the other boxes and widgets in thisQBoxLayout. Widgets and boxes with higher stretch factors grow more.
If the stretch factor is 0 and nothing else in theQBoxLayout has a stretch factor greater than zero, the space is distributed according to theQWidget:sizePolicy() of each widget that's involved.
The alignment is specified byalignment. The default alignment is 0, which means that the widget fills the entire cell.
See alsoinsertWidget(),addItem(),addLayout(),addStretch(),addSpacing(), andaddStrut().
[virtual]int QBoxLayout::count() constReimplemented fromQLayout::count().
Returns the direction of the box.addWidget() andaddSpacing() work in this direction; the stretch stretches in this direction.
See alsosetDirection(),QBoxLayout::Direction,addWidget(), andaddSpacing().
[virtual]Qt::Orientations QBoxLayout::expandingDirections() constReimplemented fromQLayoutItem::expandingDirections().
[virtual]bool QBoxLayout::hasHeightForWidth() constReimplemented fromQLayoutItem::hasHeightForWidth().
[virtual]int QBoxLayout::heightForWidth(int w) constReimplemented fromQLayoutItem::heightForWidth().
[protected]void QBoxLayout::insertItem(int index,QLayoutItem * item)Insertsitem into this box layout at positionindex. Ifindex is negative, the item is added at the end.
See alsoaddItem(),insertWidget(),insertLayout(),insertStretch(), andinsertSpacing().
Insertslayout at positionindex, with stretch factorstretch. Ifindex is negative, the layout is added at the end.
layout becomes a child of the box layout.
See alsoaddLayout() andinsertItem().
InsertsspacerItem at positionindex, with zero minimum size and stretch factor. Ifindex is negative the space is added at the end.
This function was introduced in Qt 4.4.
See alsoaddSpacerItem(),insertStretch(), andinsertSpacing().
Inserts a non-stretchable space (aQSpacerItem) at positionindex, with sizesize. Ifindex is negative the space is added at the end.
The box layout has default margin and spacing. This function adds additional space.
See alsoaddSpacing(),insertItem(), andQSpacerItem.
Inserts a stretchable space (aQSpacerItem) at positionindex, with zero minimum size and stretch factorstretch. Ifindex is negative the space is added at the end.
See alsoaddStretch(),insertItem(), andQSpacerItem.
Insertswidget at positionindex, with stretch factorstretch and alignmentalignment. Ifindex is negative, the widget is added at the end.
The stretch factor applies only in thedirection of theQBoxLayout, and is relative to the other boxes and widgets in thisQBoxLayout. Widgets and boxes with higher stretch factors grow more.
If the stretch factor is 0 and nothing else in theQBoxLayout has a stretch factor greater than zero, the space is distributed according to theQWidget:sizePolicy() of each widget that's involved.
The alignment is specified byalignment. The default alignment is 0, which means that the widget fills the entire cell.
See alsoaddWidget() andinsertItem().
[virtual]void QBoxLayout::invalidate()Reimplemented fromQLayoutItem::invalidate().
Resets cached information.
[virtual]QLayoutItem * QBoxLayout::itemAt(int index) constReimplemented fromQLayout::itemAt().
[virtual]QSize QBoxLayout::maximumSize() constReimplemented fromQLayoutItem::maximumSize().
[virtual]int QBoxLayout::minimumHeightForWidth(int w) constReimplemented fromQLayoutItem::minimumHeightForWidth().
[virtual]QSize QBoxLayout::minimumSize() constReimplemented fromQLayoutItem::minimumSize().
Sets the direction of this layout todirection.
See alsodirection().
[virtual]void QBoxLayout::setGeometry(constQRect & r)Reimplemented fromQLayoutItem::setGeometry().
ReimplementsQLayout::setSpacing(). Sets the spacing property tospacing.
See alsoQLayout::setSpacing() andspacing().
Sets the stretch factor at positionindex. tostretch.
This function was introduced in Qt 4.5.
See alsostretch().
Sets the stretch factor forwidget tostretch and returns true ifwidget is found in this layout (not including child layouts); otherwise returns false.
See alsosetAlignment().
This is an overloaded function.
Sets the stretch factor for the layoutlayout tostretch and returns true iflayout is found in this layout (not including child layouts); otherwise returns false.
[virtual]QSize QBoxLayout::sizeHint() constReimplemented fromQLayoutItem::sizeHint().
ReimplementsQLayout::spacing(). If the spacing property is valid, that value is returned. Otherwise, a value for the spacing property is computed and returned. Since layout spacing in a widget is style dependent, if the parent is a widget, it queries the style for the (horizontal or vertical) spacing of the layout. Otherwise, the parent is a layout, and it queries the parent layout for the spacing().
See alsoQLayout::spacing() andsetSpacing().
Returns the stretch factor at positionindex.
This function was introduced in Qt 4.5.
See alsosetStretch().
[virtual]QLayoutItem * QBoxLayout::takeAt(int index)Reimplemented fromQLayout::takeAt().
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.