Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

TQBoxLayout Class Reference

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

#include <ntqlayout.h>

Inherits TQLayout.

Inherited by TQHBoxLayout and TQVBoxLayout.

List of all member functions.

Public Members

Protected Members


Detailed Description

The TQBoxLayout class lines up child widgets horizontally or vertically.

TQBoxLayout 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.

Horizontal box with five child widgets

If the TQBoxLayout's orientation is 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 with five child widgets

If the TQBoxLayout's orientation is Vertical, the boxes are placed in a column, again with suitable sizes.

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

If the TQBoxLayout 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 TQBoxLayout using one of four functions:

Use insertWidget(), insertSpacing(), insertStretch() or insertLayout() to insert a box at a specified position in the layout.

TQBoxLayout also includes two margin widths:

The margin defaults to 0. The spacing defaults to the same as the margin width for a top-level layout, or to the same as the parent layout. Both are parameters to the constructor.

To remove a widget from a layout, call remove(). Calling TQWidget::hide() on a widget also effectively removes the widget from the layout until TQWidget::show() is called.

You will almost always want to use TQVBoxLayout and TQHBoxLayout rather than TQBoxLayout because of their convenient constructors.

See also TQGrid, Layout Overview, Widget Appearance and Style, and Layout Management.


Member Type Documentation

TQBoxLayout::Direction

This type is used to determine the direction of a box layout.


Member Function Documentation

TQBoxLayout::TQBoxLayout ( TQWidget * parent, Direction d, int margin = 0, int spacing = -1, const char * name = 0 )

Constructs a new TQBoxLayout with direction d and main widget parent. parent may not be 0.

The margin is the number of pixels between the edge of the widget and its managed children. The spacing is the default number of pixels between neighboring children. If spacing is -1 the value of margin is used for spacing.

name is the internal object name.

See also direction().

TQBoxLayout::TQBoxLayout ( TQLayout * parentLayout, Direction d, int spacing = -1, const char * name = 0 )

Constructs a new TQBoxLayout called name, with direction d, and inserts it into parentLayout.

The spacing is the default number of pixels between neighboring children. If spacing is -1, the layout will inherit its parent's spacing().

TQBoxLayout::TQBoxLayout ( Direction d, int spacing = -1, const char * name = 0 )

Constructs a new TQBoxLayout called name, with direction d.

If spacing is -1, the layout will inherit its parent's spacing(); otherwise spacing is used.

You must insert this box into another layout.

TQBoxLayout::~TQBoxLayout ()

Destroys this box layout.

The layout's widgets aren't destroyed.

void TQBoxLayout::addItem ( TQLayoutItem * item ) [virtual]

Adds item to the end of this box layout.

Examples: chart/optionsform.cpp and chart/setdataform.cpp.

Reimplemented from TQLayout.

void TQBoxLayout::addLayout ( TQLayout * layout, int stretch = 0 )

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

When a layout is constructed with another layout as its parent, you don't need to call addLayout(); the child layout is automatically added to the parent layout as it is constructed.

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

Examples: chart/optionsform.cpp, chart/setdataform.cpp, fonts/simple-qfont-demo/viewer.cpp, listbox/listbox.cpp, regexptester/regexptester.cpp, and tictac/tictac.cpp.

void TQBoxLayout::addSpacing ( int size )

Adds a non-stretchable space with size size to the end of this box layout. TQBoxLayout provides default margin and spacing. This function adds additional space.

See also insertSpacing() and addStretch().

Example: listbox/listbox.cpp.

void TQBoxLayout::addStretch ( int stretch = 0 )

Adds a stretchable space with zero minimum size and stretch factor stretch to the end of this box layout.

See also addSpacing().

Examples: layout/layout.cpp, listbox/listbox.cpp, regexptester/regexptester.cpp, and t13/gamebrd.cpp.

void TQBoxLayout::addStrut ( int size )

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.

void TQBoxLayout::addWidget ( TQWidget * widget, int stretch = 0, int alignment = 0 )

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 direction of the TQBoxLayout, and is relative to the other boxes and widgets in this TQBoxLayout. Widgets and boxes with higher stretch factors grow more.

If the stretch factor is 0 and nothing else in the TQBoxLayout has a stretch factor greater than zero, the space is distributed according to the TQWidget:sizePolicy() of each widget that's involved.

Alignment is specified by alignment which is a bitwise OR of TQt::AlignmentFlags values. The default alignment is 0, which means that the widget fills the entire cell.

From TQt 3.0, the alignment parameter is interpreted more aggressively than in previous versions of TQt. 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 insertWidget(), setAutoAdd(), addLayout(), and addSpacing().

Examples: chart/optionsform.cpp, checklists/checklists.cpp, layout/layout.cpp, lineedits/lineedits.cpp, listbox/listbox.cpp, t13/gamebrd.cpp, and t13/lcdrange.cpp.

Direction TQBoxLayout::direction () const

Returns the direction of the box. addWidget() and addSpacing() work in this direction; the stretch stretches in this direction.

See also TQBoxLayout::Direction, addWidget(), and addSpacing().

TQSizePolicy::ExpandData TQBoxLayout::expanding () const [virtual]

Returns whether this layout can make use of more space than sizeHint(). A value of Vertical or Horizontal means that it wants to grow in only one dimension, whereas BothDirections means that it wants to grow in both dimensions.

Reimplemented from TQLayout.

int TQBoxLayout::findWidget ( TQWidget * w )

Searches for widget w in this layout (not including child layouts).

Returns the index of w, or -1 if w is not found.

bool TQBoxLayout::hasHeightForWidth () const [virtual]

Returns TRUE if this layout's preferred height depends on its width; otherwise returns FALSE.

Reimplemented from TQLayoutItem.

int TQBoxLayout::heightForWidth ( int w ) const [virtual]

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

Reimplemented from TQLayoutItem.

void TQBoxLayout::insertItem ( int index, TQLayoutItem * item ) [protected]

Inserts item into this box layout at position index. If index is negative, the item is added at the end.

Warning: Does not call TQLayout::insertChildLayout() if item is a TQLayout.

See also addItem() and findWidget().

void TQBoxLayout::insertLayout ( int index, TQLayout * layout, int stretch = 0 )

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.

See also setAutoAdd(), insertWidget(), and insertSpacing().

void TQBoxLayout::insertSpacing ( int index, int size )

Inserts a non-stretchable space 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.

See also insertStretch().

void TQBoxLayout::insertStretch ( int index, int stretch = 0 )

Inserts a stretchable space at position index, with zero minimum size and stretch factor stretch. If index is negative the space is added at the end.

See also insertSpacing().

void TQBoxLayout::insertWidget ( int index, TQWidget * widget, int stretch = 0, int alignment = 0 )

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 direction of the TQBoxLayout, and is relative to the other boxes and widgets in this TQBoxLayout. Widgets and boxes with higher stretch factors grow more.

If the stretch factor is 0 and nothing else in the TQBoxLayout has a stretch factor greater than zero, the space is distributed according to the TQWidget:sizePolicy() of each widget that's involved.

Alignment is specified by alignment, which is a bitwise OR of TQt::AlignmentFlags values. The default alignment is 0, which means that the widget fills the entire cell.

From TQt 3.0, the alignment parameter is interpreted more aggressively than in previous versions of TQt. 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(), insertLayout(), and insertSpacing().

void TQBoxLayout::invalidate () [virtual]

Resets cached information.

Reimplemented from TQLayout.

TQSize TQBoxLayout::maximumSize () const [virtual]

Returns the maximum size needed by this box layout.

Reimplemented from TQLayout.

TQSize TQBoxLayout::minimumSize () const [virtual]

Returns the minimum size needed by this box layout.

Reimplemented from TQLayout.

void TQBoxLayout::setDirection ( Direction direction )

Sets the direction of this layout to direction.

void TQBoxLayout::setGeometry ( const TQRect & r ) [virtual]

Resizes managed widgets within the rectangle r.

Reimplemented from TQLayout.

bool TQBoxLayout::setStretchFactor ( TQWidget * w, int stretch )

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

bool TQBoxLayout::setStretchFactor ( TQLayout * l, int stretch )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the stretch factor for the layout l to stretch and returns TRUE if l is found in this layout (not including child layouts); otherwise returns FALSE.

TQSize TQBoxLayout::sizeHint () const [virtual]

Returns the preferred size of this box layout.

Reimplemented from TQLayoutItem.


This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.


Copyright © 2007 TrolltechTrademarks
TQt 3.3.8