QLayout(3) The base class of geometry managers

SYNOPSIS

#include <qlayout.h>

Inherits QObject and QLayoutItem.

Inherited by QGridLayout and QBoxLayout.

Public Members


enum ResizeMode { FreeResize, Minimum, Fixed, Auto }

QLayout ( QWidget * parent, int margin = 0, int spacing = -1, const char * name = 0 )

QLayout ( QLayout * parentLayout, int spacing = -1, const char * name = 0 )

QLayout ( int spacing = -1, const char * name = 0 )

int margin () const

int spacing () const

virtual void setMargin ( int )

virtual void setSpacing ( int )

void setResizeMode ( ResizeMode )

ResizeMode resizeMode () const

virtual void setMenuBar ( QMenuBar * w )

QMenuBar * menuBar () const

QWidget * mainWidget ()

bool isTopLevel () const

virtual void setAutoAdd ( bool b )

bool autoAdd () const

virtual void invalidate ()

bool activate ()

void add ( QWidget * w )

virtual void addItem ( QLayoutItem * item ) = 0

void remove ( QWidget * widget )

void removeItem ( QLayoutItem * item )

virtual QSizePolicy::ExpandData expanding () const

virtual QSize minimumSize () const

virtual QSize maximumSize () const

virtual void setGeometry ( const QRect & r ) = 0

virtual QLayoutIterator iterator () = 0

virtual bool isEmpty () const

bool supportsMargin () const

void setEnabled ( bool enable )

bool isEnabled () const

Properties


int margin - the width of the outside border of the layout

ResizeMode resizeMode - the resize mode of the layout

int spacing - the spacing between widgets inside the layout

Protected Members


void addChildLayout ( QLayout * l )

void deleteAllItems ()

void setSupportsMargin ( bool b )

QRect alignmentRect ( const QRect & r ) const

DESCRIPTION

The QLayout class is the base class of geometry managers.

This is an abstract base class inherited by the concrete classes, QBoxLayout and QGridLayout.

For users of QLayout subclasses or of QMainWindow there is seldom any need to use the basic functions provided by QLayout, such as setResizeMode() or setMenuBar(). See the layout overview page for more information.

To make your own layout manager, subclass QGLayoutIterator and implement the functions addItem(), sizeHint(), setGeometry(), and iterator(). You should also implement minimumSize() to ensure your layout isn't resized to zero size if there is too little space. To support children whose heights depend on their widths, implement hasHeightForWidth() and heightForWidth(). See the custom layout page for an in-depth description.

Geometry management stops when the layout manager is deleted.

See also Widget Appearance and Style and Layout Management.

Member Type Documentation

QLayout::ResizeMode

The possible values are:
QLayout::Auto - If the main widget is a top-level widget with no height-for-width (hasHeightForWidth()), this is the same as Minimium; otherwise, this is the same as FreeResize.
QLayout::Fixed - The main widget's size is set to sizeHint(); it cannot be resized at all.
QLayout::Minimum - The main widget's minimum size is set to minimumSize(); it cannot be smaller.
QLayout::FreeResize - The widget is not constrained.

MEMBER FUNCTION DOCUMENTATION

QLayout::QLayout ( QWidget * parent, int margin = 0, int spacing = -1, const char * name = 0 )

Constructs a new top-level QLayout called name, with main widget parent. parent may not be 0.

The margin is the number of pixels between the edge of the widget and the managed children. The spacing sets the value of spacing(), which gives the spacing between the managed widgets. If spacing is -1 (the default), spacing is set to the value of margin.

There can be only one top-level layout for a widget. It is returned by QWidget::layout()

QLayout::QLayout ( QLayout * parentLayout, int spacing = -1, const char * name = 0 )

Constructs a new child QLayout called name, and places it inside parentLayout by using the default placement defined by addItem().

If spacing is -1, this QLayout inherits parentLayout's spacing(), otherwise the value of spacing is used.

QLayout::QLayout ( int spacing = -1, const char * name = 0 )

Constructs a new child QLayout called name. If spacing is -1, this QLayout inherits its parent's spacing(); otherwise the value of spacing is used.

This layout has to be inserted into another layout before geometry management will work.

bool QLayout::activate ()

Redoes the layout for mainWidget(). You should generally not need to call this because it is automatically called at the most appropriate times.

However, if you set up a QLayout for a visible widget without resizing that widget, you will need to call this function in order to lay it out.

See also QWidget::updateGeometry().

Examples:

void QLayout::add ( QWidget * w )

Adds widget w to this layout in a manner specific to the layout. This function uses addItem().

Examples:

void QLayout::addChildLayout ( QLayout * l ) [protected]

This function is called from addLayout() functions in subclasses to add layout l as a sub-layout.

void QLayout::addItem ( QLayoutItem * item ) [pure virtual]

Implemented in subclasses to add an item. How it is added is specific to each subclass.

The ownership of item is transferred to the layout, and it's the layout's responsibility to delete it.

Examples:

Reimplemented in QGridLayout and QBoxLayout.

QRect QLayout::alignmentRect ( const QRect & r ) const [protected]

Returns the rectangle that should be covered when the geometry of this layout is set to r, provided that this layout supports setAlignment().

The result is derived from sizeHint() and expanding(). It is never larger than r.

bool QLayout::autoAdd () const

Returns TRUE if this layout automatically grabs all new mainWidget()'s new children and adds them as defined by addItem(); otherwise returns FALSE. This has effect only for top-level layouts, i.e. layouts that are direct children of their mainWidget().

autoAdd() is disabled by default.

Note that a top-level layout is not necessarily associated with the top-level widget.

See also setAutoAdd().

void QLayout::deleteAllItems () [protected]

Removes and deletes all items in this layout.

QSizePolicy::ExpandData QLayout::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.

The default implementation returns BothDirections.

Examples:

Reimplemented from QLayoutItem.

Reimplemented in QGridLayout and QBoxLayout.

void QLayout::invalidate () [virtual]

Invalidates cached information. Reimplementations must call this.

Reimplemented from QLayoutItem.

Reimplemented in QGridLayout and QBoxLayout.

bool QLayout::isEmpty () const [virtual]

Returns TRUE if this layout is empty. The default implementation returns FALSE.

Reimplemented from QLayoutItem.

bool QLayout::isEnabled () const

Returns TRUE if the layout is enabled; otherwise returns FALSE.

See also setEnabled().

bool QLayout::isTopLevel () const

Returns TRUE if this layout is a top-level layout, i.e. not a child of another layout; otherwise returns FALSE.

QLayoutIterator QLayout::iterator () [pure virtual]

Implemented in subclasses to return an iterator that iterates over this layout's children.

A typical implementation will be:


QLayoutIterator MyLayout::iterator()
{
QGLayoutIterator *i = new MyLayoutIterator( internal_data );
return QLayoutIterator( i );
}
where MyLayoutIterator is a subclass of QGLayoutIterator.

Examples:

Reimplemented from QLayoutItem.

QWidget * QLayout::mainWidget ()

Returns the main widget (parent widget) of this layout, or 0 if this layout is a sub-layout that is not yet inserted.

int QLayout::margin () const

Returns the width of the outside border of the layout. See the "margin" property for details.

QSize QLayout::maximumSize () const [virtual]

Returns the maximum size of this layout. This is the largest size that the layout can have while still respecting the specifications. Does not include what's needed by margin() or menuBar().

The default implementation allows unlimited resizing.

Reimplemented from QLayoutItem.

Reimplemented in QGridLayout and QBoxLayout.

QMenuBar * QLayout::menuBar () const

Returns the menu bar set for this layout, or 0 if no menu bar is set.

QSize QLayout::minimumSize () const [virtual]

Returns the minimum size of this layout. This is the smallest size that the layout can have while still respecting the specifications. Does not include what's needed by margin() or menuBar().

The default implementation allows unlimited resizing.

Examples:

Reimplemented from QLayoutItem.

Reimplemented in QGridLayout and QBoxLayout.

void QLayout::remove ( QWidget * widget )

Removes the widget widget from the layout. After this call, it is the caller's responsibility to give the widget a reasonable geometry or to put the widget back into a layout.

See also removeItem(), QWidget::geometry, and add().

void QLayout::removeItem ( QLayoutItem * item )

Removes the layout item item from the layout. It is the caller's responsibility to delete the item.

Notice that item can be a layout (since QLayout inherits QLayoutItem).

See also remove() and addItem().

ResizeMode QLayout::resizeMode () const

Returns the resize mode of the layout. See the "resizeMode" property for details.

void QLayout::setAutoAdd ( bool b ) [virtual]

If b is TRUE, auto-add is enabled; otherwise auto-add is disabled.

Warning: If auto-add is enabled, you cannot set stretch factors on the child widgets until the widgets are actually inserted in the layout (after control returned to the event loop). We therefore recommend that you avoid the auto-add feature in new programs.

See also autoAdd().

Examples:

void QLayout::setEnabled ( bool enable )

Enables this layout if enable is TRUE, otherwise disables it.

An enabled layout adjusts dynamically to changes; a disabled layout acts as if it did not exist.

By default all layouts are enabled.

See also isEnabled().

void QLayout::setGeometry ( const QRect & r ) [pure virtual]

This function is reimplemented in subclasses to perform layout.

The default implementation maintains the geometry() information given by rect r. Reimplementors must call this function.

Examples:

Reimplemented from QLayoutItem.

Reimplemented in QGridLayout and QBoxLayout.

void QLayout::setMargin ( int ) [virtual]

Sets the width of the outside border of the layout. See the "margin" property for details.

void QLayout::setMenuBar ( QMenuBar * w ) [virtual]

Makes the geometry manager take account of the menu bar w. All child widgets are placed below the bottom edge of the menu bar.

A menu bar does its own geometry management: never do addWidget() on a QMenuBar.

Examples:

void QLayout::setResizeMode ( ResizeMode )

Sets the resize mode of the layout. See the "resizeMode" property for details.

void QLayout::setSpacing ( int ) [virtual]

Sets the spacing between widgets inside the layout. See the "spacing" property for details.

void QLayout::setSupportsMargin ( bool b ) [protected]

Sets the value returned by supportsMargin(). If b is TRUE, margin() handling is implemented by the subclass. If b is FALSE (the default), QLayout will add margin() around top-level layouts.

If b is TRUE, margin handling needs to be implemented in setGeometry(), maximumSize(), minimumSize(), sizeHint() and heightForWidth().

See also supportsMargin().

int QLayout::spacing () const

Returns the spacing between widgets inside the layout. See the "spacing" property for details.

bool QLayout::supportsMargin () const

Returns TRUE if this layout supports QLayout::margin on non-top-level layouts; otherwise returns FALSE.

See also margin.

Property Documentation

int margin

This property holds the width of the outside border of the layout.

For some layout classes this property has an effect only on top-level layouts; QBoxLayout and QGridLayout support margins for child layouts. The default value is 0.

See also spacing.

Set this property's value with setMargin() and get this property's value with margin().

ResizeMode resizeMode

This property holds the resize mode of the layout.

The default mode is Auto.

See also QLayout::ResizeMode.

Set this property's value with setResizeMode() and get this property's value with resizeMode().

int spacing

This property holds the spacing between widgets inside the layout.

The default value is -1, which signifies that the layout's spacing should not override the widget's spacing.

See also margin.

Set this property's value with setSpacing() and get this property's value with spacing().

COPYRIGHT

Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.

AUTHOR

Generated automatically from the source code.

BUGS

If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you.

The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech.

If you find errors in this manual page, please report them to [email protected]. Please include the name of the manual page (qlayout.3qt) and the Qt version (3.3.8).