QtBase
v6.3.1
|
The QBoxLayout class lines up child widgets horizontally or vertically. More...
#include <qboxlayout.h>
Public Types | |
enum | Direction { LeftToRight , RightToLeft , TopToBottom , BottomToTop , Down = TopToBottom , Up = BottomToTop } |
Public Types inherited from QLayout | |
enum | SizeConstraint { SetDefaultConstraint , SetNoConstraint , SetMinimumSize , SetFixedSize , SetMaximumSize , SetMinAndMaxSize } |
The QBoxLayout class lines up child widgets horizontally or vertically.
\inmodule QtWidgets
QBoxLayout takes the space it gets (from its parent layout or from the parentWidget()), divides it up into a row of boxes, and makes each managed widget fill one box.
Horizontal box layout with five child widgets
If the QBoxLayout's orientation is Qt::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).
Vertical box layout with five child widgets
If the QBoxLayout's orientation is Qt::Vertical, the boxes are placed in a column, again with suitable sizes.
The easiest way to create a QBoxLayout is to use one of the convenience classes, e.g. QHBoxLayout (for Qt::Horizontal boxes) or QVBoxLayout (for Qt::Vertical boxes). You can also use the QBoxLayout constructor directly, specifying its direction as LeftToRight, RightToLeft, TopToBottom, or BottomToTop.
If the 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:
\list
Use insertWidget(), insertSpacing(), insertStretch() or insertLayout() to insert a box at a specified position in the layout.
QBoxLayout also includes two margin widths:
\list
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, call removeWidget(). Calling QWidget::hide() on a widget also effectively removes the widget from the layout until QWidget::show() is called.
You will almost always want to use QVBoxLayout and QHBoxLayout rather than QBoxLayout because of their convenient constructors.
Definition at line 56 of file qboxlayout.h.
This type is used to determine the direction of a box layout.
\value LeftToRight Horizontal from left to right. \value RightToLeft Horizontal from right to left. \value TopToBottom Vertical from top to bottom. \value BottomToTop Vertical from bottom to top.
\omitvalue Down \omitvalue Up
Enumerator | |
---|---|
LeftToRight | |
RightToLeft | |
TopToBottom | |
BottomToTop | |
Down | |
Up |
Definition at line 61 of file qboxlayout.h.
Constructs a new QBoxLayout with direction dir and parent widget parent.
The layout is set directly as the top-level layout for parent. There can be only one top-level layout for a widget. It is returned by QWidget::layout().
Definition at line 556 of file qboxlayout.cpp.
QBoxLayout::~QBoxLayout | ( | ) |
Destroys this box layout.
The layout's widgets aren't destroyed.
Definition at line 570 of file qboxlayout.cpp.
|
overridevirtual |
\reimp
Implements QLayout.
Definition at line 832 of file qboxlayout.cpp.
Adds layout to the end of the box, with serial stretch factor stretch.
Definition at line 1056 of file qboxlayout.cpp.
void QBoxLayout::addSpacerItem | ( | QSpacerItem * | spacerItem | ) |
Adds spacerItem to the end of this box layout.
Definition at line 1020 of file qboxlayout.cpp.
void QBoxLayout::addSpacing | ( | int | size | ) |
Adds a non-stretchable space (a QSpacerItem) with size size to the end of this box layout. QBoxLayout provides default margin and spacing. This function adds additional space.
Definition at line 997 of file qboxlayout.cpp.
void QBoxLayout::addStretch | ( | int | stretch = 0 | ) |
Adds a stretchable space (a QSpacerItem) with zero minimum size and stretch factor stretch to the end of this box layout.
Definition at line 1008 of file qboxlayout.cpp.
void QBoxLayout::addStrut | ( | int | size | ) |
Limits the perpendicular dimension of the box (e.g. height if the box is \l LeftToRight) to a minimum of size. Other constraints may increase the limit.
Definition at line 1068 of file qboxlayout.cpp.
void QBoxLayout::addWidget | ( | QWidget * | widget, |
int | stretch = 0 , |
||
Qt::Alignment | alignment = Qt::Alignment() |
||
) |
Adds widget to the end of this box layout, with a stretch factor of stretch and alignment alignment.
The stretch factor applies only in the \l{direction()}{direction} of the QBoxLayout, and is relative to the other boxes and widgets in this QBoxLayout. Widgets and boxes with higher stretch factors grow more.
If the stretch factor is 0 and nothing else in the QBoxLayout has a stretch factor greater than zero, the space is distributed according to the QWidget:sizePolicy() of each widget that's involved.
The alignment is specified by alignment. The default alignment is 0, which means that the widget fills the entire cell.
Definition at line 1045 of file qboxlayout.cpp.
|
overridevirtual |
\reimp
Implements QLayout.
Definition at line 707 of file qboxlayout.cpp.
QBoxLayout::Direction QBoxLayout::direction | ( | ) | const |
Returns the direction of the box. addWidget() and addSpacing() work in this direction; the stretch stretches in this direction.
Definition at line 1212 of file qboxlayout.cpp.
|
overridevirtual |
|
overridevirtual |
\reimp
Reimplemented from QLayoutItem.
Definition at line 655 of file qboxlayout.cpp.
|
overridevirtual |
\reimp
Reimplemented from QLayoutItem.
Definition at line 666 of file qboxlayout.cpp.
void QBoxLayout::insertItem | ( | int | index, |
QLayoutItem * | item | ||
) |
Inserts item into this box layout at position index. If index is negative, the item is added at the end.
Definition at line 847 of file qboxlayout.cpp.
Inserts layout at position index, with stretch factor stretch. If index is negative, the layout is added at the end.
layout becomes a child of the box layout.
Definition at line 939 of file qboxlayout.cpp.
void QBoxLayout::insertSpacerItem | ( | int | index, |
QSpacerItem * | spacerItem | ||
) |
Inserts spacerItem at position index, with zero minimum size and stretch factor. If index is negative the space is added at the end.
Definition at line 919 of file qboxlayout.cpp.
void QBoxLayout::insertSpacing | ( | int | index, |
int | size | ||
) |
Inserts a non-stretchable space (a QSpacerItem) at position index, with size size. If index is negative the space is added at the end.
The box layout has default margin and spacing. This function adds additional space.
Definition at line 867 of file qboxlayout.cpp.
void QBoxLayout::insertStretch | ( | int | index, |
int | stretch = 0 |
||
) |
Inserts a stretchable space (a QSpacerItem) at position index, with zero minimum size and stretch factor stretch. If index is negative the space is added at the end.
Definition at line 892 of file qboxlayout.cpp.
void QBoxLayout::insertWidget | ( | int | index, |
QWidget * | widget, | ||
int | stretch = 0 , |
||
Qt::Alignment | alignment = Qt::Alignment() |
||
) |
Inserts widget at position index, with stretch factor stretch and alignment alignment. If index is negative, the widget is added at the end.
The stretch factor applies only in the \l{direction()}{direction} of the QBoxLayout, and is relative to the other boxes and widgets in this QBoxLayout. Widgets and boxes with higher stretch factors grow more.
If the stretch factor is 0 and nothing else in the QBoxLayout has a stretch factor greater than zero, the space is distributed according to the QWidget:sizePolicy() of each widget that's involved.
The alignment is specified by alignment. The default alignment is 0, which means that the widget fills the entire cell.
Definition at line 973 of file qboxlayout.cpp.
|
overridevirtual |
Resets cached information.
Reimplemented from QLayoutItem.
Definition at line 697 of file qboxlayout.cpp.
|
overridevirtual |
\reimp
Implements QLayout.
Definition at line 716 of file qboxlayout.cpp.
|
overridevirtual |
\reimp
Implements QLayoutItem.
Definition at line 637 of file qboxlayout.cpp.
|
overridevirtual |
\reimp
Reimplemented from QLayoutItem.
Definition at line 685 of file qboxlayout.cpp.
|
overridevirtual |
Sets the direction of this layout to direction.
Definition at line 1164 of file qboxlayout.cpp.
\reimp
Reimplemented from QLayout.
Definition at line 760 of file qboxlayout.cpp.
|
overridevirtual |
Reimplements QLayout::setSpacing(). Sets the spacing property to spacing.
Reimplemented from QLayout.
Definition at line 605 of file qboxlayout.cpp.
void QBoxLayout::setStretch | ( | int | index, |
int | stretch | ||
) |
Sets the stretch factor at position index. to stretch.
Definition at line 1135 of file qboxlayout.cpp.
bool QBoxLayout::setStretchFactor | ( | QLayout * | layout, |
int | stretch | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Sets the stretch factor for the layout layout to stretch and returns true
if layout is found in this layout (not including child layouts); otherwise returns false
.
Definition at line 1113 of file qboxlayout.cpp.
bool QBoxLayout::setStretchFactor | ( | QWidget * | widget, |
int | stretch | ||
) |
Sets the stretch factor for widget to stretch and returns true if widget is found in this layout (not including child layouts); otherwise returns false
.
Definition at line 1090 of file qboxlayout.cpp.
|
overridevirtual |
|
overridevirtual |
Reimplements QLayout::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().
Reimplemented from QLayout.
Definition at line 587 of file qboxlayout.cpp.
int QBoxLayout::stretch | ( | int | index | ) | const |
Returns the stretch factor at position index.
Definition at line 1153 of file qboxlayout.cpp.
|
overridevirtual |
\reimp
Implements QLayout.
Definition at line 725 of file qboxlayout.cpp.