Qt logo

QBoxLayout Class Reference


The QBoxLayout class lines up child widgets horizontally or vertically. More...

#include <qlayout.h>

Inherits QLayout.

Inherited by QHBoxLayout and QVBoxLayout.

List of all member functions.

Public Members


Detailed Description

The QBoxLayout class lines up child widgets horizontally or vertically.

QBoxLayout takes the space it gets (from its parent layout or from the mainWidget()), divides it up into a row of boxes and makes each managed widget fill one box.

If the QBoxLayout is Horizontal, the boxes are beside each other, with suitable sizes. Each widget (or other box) will get at least its minimum sizes and at most its maximum size, and any excess space is shared according to the stretch factors (more about that below).

If the QBoxLayout is Vertical, the boxes are above and below each other, again with suitable sizes.

The easiest way to create a QBoxLayout is to use one of the convenience classes QHBoxLayout (for Horizontal boxes) or QVBoxLayout (for Vertical boxes). You can also use the QBoxLayout constructor directly, specifying its direction as LeftToRight, Down, RightToLeft or Up.

If the QBoxLayout is not the top-level layout (ie. 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 that, you can add boxes to the QBoxLayout using one of four functions:

QBoxLayout also includes two margin widths: The border width and the inter-box width. The border width is the width of the reserved space along each of the QBoxLayout's four sides. The intra-widget width is the width of the automatically allocated spacing between neighbouring boxes. (You can use addSpacing() to get more space.)

The border width defaults to 0, and the intra-widget width defaults to the same as the border width. Both are set using arguments to the constructor.

You will almost always want to use the convenience classes for QBoxLayout: QVBoxLayout and QHBoxLayout, because of their simpler constructors.

See also the Layout Overview documentation.

Examples: layout/layout.cpp popup/popup.cpp customlayout/main.cpp


Member Function Documentation

QBoxLayout::QBoxLayout(QLayout*parentLayout, Directiond, intspace=-1, constchar*name=0)

Creates a new QBoxLayout with direction d and inserts it into parentLayout.

QBoxLayout::QBoxLayout(QWidget*parent, Directiond, intborder=0, intspace=-1, constchar*name=0)

Creates a new QBoxLayout with direction d and main widget parent. parent may not be 0.

border is the number of pixels between the edge of the widget and the managed children. space is the default number of pixels between neighbouring children. If space is -1 the value of border is used.

name is the internal object name

See also: direction().

QBoxLayout::QBoxLayout(Directiond, intspace=-1, constchar*name=0)

If space is -1, this QBoxLayout will inherit its parent's spacing(), otherwise space is used.

You have to insert this box into another layout.

Examples: layout/layout.cpp

QBoxLayout::~QBoxLayout()

Destroys this box.

voidQBoxLayout::addItem(QLayoutItem*item) [virtual]

Adds item to this box.

Reimplemented from QLayout.

voidQBoxLayout::addLayout(QLayout*layout, intstretch=0)

Adds layout to the box, with serial stretch factor stretch.

See also: setAutoAdd(), addWidget() and addSpacing().

voidQBoxLayout::addSpacing(intsize)

Adds a non-stretchable space with size size. QBoxLayout gives default border and spacing. This function adds additional space.

See also: addStretch().

voidQBoxLayout::addStretch(intstretch=0)

Adds a stretchable space with zero minimum size and stretch factor stretch.

See also: addSpacing().

voidQBoxLayout::addStrut(intsize)

Limits the perpendicular dimension of the box (e.g. height if the box is LeftToRight) to a minimum of size. Other constraints may increase the limit.

voidQBoxLayout::addWidget(QWidget*widget, intstretch=0, intalignmnt=0)

Adds widget to the box, with stretch factor stretch and alignment alignmnt.

The stretch factor applies only in the direction of the QBoxLayout, and is relative to the other boxes and widgets in this QBoxLayout. Widgets and boxes with higher stretch factor 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.

Alignment is specified by alignmnt which takes the same arguments as QLabel::setAlignment(). The default alignment is 0, which means that the widget fills the entire cell.

Note: The alignment parameter is interpreted more aggressively than in previous versions of Qt. A non-default alignment now indicates that the widget should not grow to fill the available space, but should be sized according to sizeHint().

See also: setAutoAdd(), addLayout() and addSpacing().

Examples: layout/layout.cpp popup/popup.cpp scrollview/scrollview.cpp customlayout/main.cpp

boolQBoxLayout::hasHeightForWidth()const [virtual]

Returns whether this layout's preferred height depends on its width.

Reimplemented from QLayoutItem.

intQBoxLayout::heightForWidth(intw)const [virtual]

Returns the layout's preferred height when it is w pixels wide.

Reimplemented from QLayoutItem.

voidQBoxLayout::invalidate() [virtual]

Resets cached information.

Reimplemented from QLayoutItem.

QLayoutIteratorQBoxLayout::iterator() [virtual]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QLayoutItem.

QSizeQBoxLayout::maximumSize()const [virtual]

Returns the maximum size needed by this box.

Reimplemented from QLayoutItem.

QSizeQBoxLayout::minimumSize()const [virtual]

Returns the minimum size needed by this box.

Reimplemented from QLayoutItem.

voidQBoxLayout::setGeometry(constQRect&s) [virtual]

Resizes managed widgets within the rectangle s.

Reimplemented from QLayoutItem.

boolQBoxLayout::setStretchFactor(QWidget*w, intstretch)

Sets the stretch factor for widget w to stretch and returns TRUE, if w is found in this layout (not including child layouts).

Returns FALSE if w is not found.

QSizeQBoxLayout::sizeHint()const

Returns the preferred size of this grid.


Search the documentation, FAQ, qt-interest archive and more (uses www.troll.no):


This file is part of the Qt toolkit, copyright © 1995-99 Troll Tech, all rights reserved.


Copyright 1999 Troll TechTrademarks
Qt version 2.0.2