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

# QStackedLayout Class Reference

The QStackedLayout class maintains a stack of widgets where only the top widget is visible. More...

    #include <QStackedLayout>

Part of the QtGui module.

Inherits QLayout.

- List of all members, including inherited members

### Properties

- count : const int
- currentIndex : int

- 3 properties inherited from QLayout
- 1 property inherited from QObject

### Public Functions

- QStackedLayout ()
- QStackedLayout ( QWidget * parent )
- QStackedLayout ( QLayout * parentLayout )
- ~QStackedLayout ()
- int addWidget ( QWidget * w )
- virtual int count () const
- int currentIndex () const
- QWidget * currentWidget () const
- int insertWidget ( int index, QWidget * w )
- QWidget * widget ( int index ) const

- 29 public functions inherited from QLayout
- 28 public functions inherited from QObject
- 16 public functions inherited from QLayoutItem

### Public Slots

- void setCurrentIndex ( int )

- 1 public slot inherited from QObject

### Signals

- void widgetRemoved ( int index )

- 1 signal inherited from QObject

### Additional Inherited Members

- 1 static public member inherited from QLayout
- 4 static public members inherited from QObject
- 3 protected functions inherited from QLayout
- 7 protected functions inherited from QObject

## Detailed Description

The QStackedLayout class maintains a stack of widgets where only the top widget is visible.

QStackedLayout places all the widgets it is responsible for on top of each other, so only the top one is visible to the user at any one time. Widget positions are given by positive integer indexes starting at 0; the widget on top has index position 0.

Widgets are added at the the end of the stack with addWidget(), or inserted in the stack with insertWidget(). The current widget is returned by currentWidget(), and its index is returned by currentIndex(). The index position of a given widget is returned by indexOf(), and the widget at a given index position by widget(). The number of widgets in the stack is returned by count(). The top widget is set with setCurrentIndex(). If a widget is removed (e.g. with QLayout::removeWidget()), the widgetRemoved() signal is emitted.

See also QStackedWidget.

## Property Documentation

### count : const int

This property holds the number of widgets contained in the layout.

Access functions:

- virtual int count () const

### currentIndex : int

This property holds the index position of the current widget.

The current index is -1 if there is no current widget, for example if the stack is empty.

Access functions:

- int currentIndex () const
- void setCurrentIndex ( int )

See also currentWidget() and indexOf().

## Member Function Documentation

### QStackedLayout::QStackedLayout ()

Constructs a new QStackedLayout

### QStackedLayout::QStackedLayout ( QWidget * parent )

Constructs a new QStackedLayout with the given parent.

### QStackedLayout::QStackedLayout ( QLayout * parentLayout )

Constructs a new QStackedLayout and inserts it into the given parentLayout.

### QStackedLayout::~QStackedLayout ()

Destroys this QStackedLayout.

The layout's widgets are not destroyed.

### int QStackedLayout::addWidget ( QWidget * w )

Adds widget w at the end of this layout stack and returns the index position of w.

The very first widget that is added becomes the initial current widget and is placed in index position 0 (i.e. on top).

See also insertWidget().

### QWidget * QStackedLayout::currentWidget () const

Returns the current widget, or 0 if there are no widgets in this layout. Equivalent to `widget(currentIndex())`.

### int QStackedLayout::insertWidget ( int index, QWidget * w )

Inserts widget w to this layout at position index. If index is out of range, the widget is appended. Returns the index position of w.

The very first widget that is added becomes the initial current widget and is placed in index position 0 (i.e. on top).

See also addWidget().

### QWidget * QStackedLayout::widget ( int index ) const

Returns the widget at position index, or 0 if there is no widget at the given position.

### void QStackedLayout::widgetRemoved ( int index ) `[signal]`

This signal is emitted if a widget is removed from the stack, e.g. with QLayout::removeWidget(). The position that the removed widget occupied in the stack is given by index.