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

# QStackedBox Class Reference

The QStackedBox class provides a stack of widgets where only the top widget is visible. More...

    #include <QStackedBox>

Inherits QFrame.

- List of all members, including inherited members

### Writable Properties

- currentIndex : int

- 5 writable properties inherited from QFrame
- 33 writable properties inherited from QWidget
- 1 writable property inherited from QObject

### Read-Only Properties

- count : int

- 1 read-only property inherited from QFrame
- 24 read-only properties inherited from QWidget

### Public Functions

- QStackedBox ( QWidget * parent = 0 )
- ~QStackedBox ()
- int addWidget ( QWidget * w )
- QWidget * currentWidget () const
- int indexOf ( QWidget * w ) const
- int insertWidget ( int index, QWidget * w )
- void removeWidget ( QWidget * w )
- QWidget * widget ( int index ) const

- 2 public functions inherited from QFrame
- 83 public functions inherited from QWidget
- 24 public functions inherited from QObject
- 2 public functions inherited from QPaintDevice

### Public Slots

- void setCurrentIndex ( int )

- 16 public slots inherited from QWidget
- 1 public slot inherited from QObject

### Signals

- void currentChanged ( int index )
- void widgetRemoved ( int index )

- 1 signal inherited from QObject

### Static Public Members

- 4 static public members inherited from QWidget
- 4 static public members inherited from QObject

### Protected Functions

- 44 protected functions inherited from QWidget
- 9 protected functions inherited from QObject

## Detailed Description

The QStackedBox class provides a stack of widgets where only the top widget is visible.

A stacked box provides a container for a number of child widgets, keeping all of these hidden except the widget at the top of the stack. It can be used to create a user interface similar to the one provided by QTabWidget.

A stacked box can be constructed and populated with a number of child widgets, each of which is typically created without a parent widget:

        QStackedBox *pages = new QStackedBox(this);
        pages->addWidget(firstPageWidget);
        pages->addWidget(secondPageWidget);
        pages->addWidget(thirdPageWidget);

The top widget in the stack is the currentWidget(). It can be changed by setting the currentIndex property, using setCurrentIndex(). The index of a given widget inside the stacked box is retrieved with indexOf(). The widget() function returns the widget at a given index position.

It is often useful to be able to control the current widget from other widgets. For example, a combobox could be used to hold the titles of the widgets in a stacked box, and used to change the current widget when an item is selected. This would be achieved by connecting its activated() signal to the setCurrent() slot of the stacked box:

        QComboBox *pageComboBox = new QComboBox(this);
        pageComboBox->insertItem("Page 1");
        pageComboBox->insertItem("Page 2");
        pageComboBox->insertItem("Page 3");
        connect(pageComboBox, SIGNAL(activated(int)),
                pages, SLOT(setCurrentIndex(int)));

If you just need a stacked layout (not a widget), use QStackedLayout instead.

See also QTabWidget.

## Property Documentation

### count : int

This property holds the number of widgets in this layout.

Access functions:

- 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. The widget at index position 0 is the one that is on top (i.e. the one that is visible).

Access functions:

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

See also currentWidget() and indexOf().

## Member Function Documentation

### QStackedBox::QStackedBox ( QWidget * parent = 0 )

Constructs a new QStackedBox as a child of parent.

### QStackedBox::~QStackedBox ()

Destroys the object and frees any allocated resources.

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

Adds w to this box. The first widget added becomes the initial current widget. Returns the index of w in this box.

### void QStackedBox::currentChanged ( int index ) `[signal]`

This signal is emitted when the current widget is changed. The parameter holds the index of the new current widget, or -1 if there isn't a new one (for example, if there are no widgets in the stacked box).

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

Returns the current widget, or 0 if there are no child widgets.

### int QStackedBox::indexOf ( QWidget * w ) const

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

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

Inserts w to this box at position index. If index is out of range, the widget gets appened. The first widget added becomes the initial current widget. Returns the index of w in this box.

### void QStackedBox::removeWidget ( QWidget * w )

Removes widget w from this layout, but does not delete it.

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

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

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

This signal is emitted when the widget at position index is removed.