Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions | ![]() |
The QStackedWidget class provides a stack of widgets where only the top widget is visible. More...
#include <QStackedWidget>
Inherits QFrame.
The QStackedWidget 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:
QStackedWidget *pages = new QStackedWidget(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.
This property holds the number of widgets in this layout.
Access functions:
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:
See also currentWidget() and indexOf().
Constructs a new QStackedWidget as a child of parent.
Destroys the object and frees any allocated resources.
Adds w to this box. The first widget added becomes the initial current widget. Returns the index of w in this box.
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).
Returns the current widget, or 0 if there are no child widgets.
Returns the index of w, or -1 if w is not a child.
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.
Removes widget w from this layout, but does not delete it.
Returns the widget at position index, or 0 if there is no such widget.
This signal is emitted when the widget at position index is removed.
Copyright © 2004 Trolltech | Trademarks | Qt 4.0.0-b1 |