Home · Overviews · Examples 

QBoxLayout Class Reference
[com.trolltech.qt.gui module]

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

Inherits QLayout.

Inherited by QHBoxLayout and QVBoxLayout.


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 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:

Use insertWidget, insertSpacing, insertStretch or insertLayout 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, 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.

See also QGridLayout, QStackedLayout, and Layout Classes.


Copyright © 2008 Trolltech Trademarks
Qt Jambi 4.3.5_01