
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQStackedLayout class provides a stack of widgets where only one widget is visible at a time.More...
| Header: | #include <QStackedLayout> |
| Inherits: | QLayout |
| enum | StackingMode { StackOne, StackAll } |
| QStackedLayout() | |
| QStackedLayout(QWidget * parent) | |
| QStackedLayout(QLayout * parentLayout) | |
| ~QStackedLayout() | |
| int | addWidget(QWidget * widget) |
| int | currentIndex() const |
| QWidget * | currentWidget() const |
| int | insertWidget(int index, QWidget * widget) |
| void | setStackingMode(StackingMode stackingMode) |
| StackingMode | stackingMode() const |
| QWidget * | widget(int index) const |
| virtual void | addItem(QLayoutItem * item) |
| virtual int | count() const |
| virtual QLayoutItem * | itemAt(int index) const |
| virtual QSize | minimumSize() const |
| virtual void | setGeometry(const QRect & rect) |
| virtual QSize | sizeHint() const |
| virtual QLayoutItem * | takeAt(int index) |
| void | setCurrentIndex(int index) |
| void | setCurrentWidget(QWidget * widget) |
| void | currentChanged(int index) |
| void | widgetRemoved(int index) |
TheQStackedLayout class provides a stack of widgets where only one widget is visible at a time.
QStackedLayout can be used to create a user interface similar to the one provided byQTabWidget. There is also a convenienceQStackedWidget class built on top ofQStackedLayout.
AQStackedLayout can be populated with a number of child widgets ("pages"). For example:
QWidget*firstPageWidget=newQWidget;QWidget*secondPageWidget=newQWidget;QWidget*thirdPageWidget=newQWidget;QStackedLayout*stackedLayout=newQStackedLayout; stackedLayout->addWidget(firstPageWidget); stackedLayout->addWidget(secondPageWidget); stackedLayout->addWidget(thirdPageWidget);QVBoxLayout*mainLayout=newQVBoxLayout; mainLayout->addLayout(stackedLayout); setLayout(mainLayout);
QStackedLayout provides no intrinsic means for the user to switch page. This is typically done through aQComboBox or aQListWidget that stores the titles of theQStackedLayout's pages. For example:
QComboBox*pageComboBox=newQComboBox; pageComboBox->addItem(tr("Page 1")); pageComboBox->addItem(tr("Page 2")); pageComboBox->addItem(tr("Page 3")); connect(pageComboBox, SIGNAL(activated(int)), stackedLayout, SLOT(setCurrentIndex(int)));
When populating a layout, the widgets are added to an internal list. TheindexOf() function returns the index of a widget in that list. The widgets can either be added to the end of the list using theaddWidget() function, or inserted at a given index using theinsertWidget() function. TheremoveWidget() function removes the widget at the given index from the layout. The number of widgets contained in the layout, can be obtained using thecount() function.
Thewidget() function returns the widget at a given index position. The index of the widget that is shown on screen is given bycurrentIndex() and can be changed usingsetCurrentIndex(). In a similar manner, the currently shown widget can be retrieved using thecurrentWidget() function, and altered using thesetCurrentWidget() function.
Whenever the current widget in the layout changes or a widget is removed from the layout, thecurrentChanged() andwidgetRemoved() signals are emitted respectively.
See alsoQStackedWidget andQTabWidget.
This enum specifies how the layout handles its child widgets regarding their visibility.
| Constant | Value | Description |
|---|---|---|
QStackedLayout::StackOne | 0 | Only the current widget is visible. This is the default. |
QStackedLayout::StackAll | 1 | All widgets are visible. The current widget is merely raised. |
This enum was introduced or modified in Qt 4.4.
This property holds the number of widgets contained in the layout.
Access functions:
| virtual int | count() const |
See alsocurrentIndex() andwidget().
This property holds the index position of the widget that is visible.
The current index is -1 if there is no current widget.
Access functions:
| int | currentIndex() const |
| void | setCurrentIndex(int index) |
Notifier signal:
| void | currentChanged(int index) |
See alsocurrentWidget() andindexOf().
This property determines the way visibility of child widgets are handled.
The default value isStackOne. Setting the property toStackAll allows you to make use of the layout for overlay widgets that do additional drawing on top of other widgets, for example, graphical editors.
This property was introduced in Qt 4.4.
Access functions:
| StackingMode | stackingMode() const |
| void | setStackingMode(StackingMode stackingMode) |
Constructs aQStackedLayout with no parent.
ThisQStackedLayout must be installed on a widget later on to become effective.
See alsoaddWidget() andinsertWidget().
Constructs a newQStackedLayout with the givenparent.
This layout will install itself on theparent widget and manage the geometry of its children.
Constructs a newQStackedLayout and inserts it into the givenparentLayout.
Destroys thisQStackedLayout. Note that the layout's widgets arenot destroyed.
[virtual]void QStackedLayout::addItem(QLayoutItem * item)Reimplemented fromQLayout::addItem().
Adds the givenwidget to the end of this layout and returns the index position of thewidget.
If theQStackedLayout is empty before this function is called, the givenwidget becomes the current widget.
See alsoinsertWidget(),removeWidget(), andsetCurrentWidget().
Returns the current widget, or 0 if there are no widgets in this layout.
See alsocurrentIndex() andsetCurrentWidget().
Inserts the givenwidget at the givenindex in thisQStackedLayout. Ifindex is out of range, the widget is appended (in which case it is the actual index of thewidget that is returned).
If theQStackedLayout is empty before this function is called, the givenwidget becomes the current widget.
Inserting a new widget at an index less than or equal to the current index will increment the current index, but keep the current widget.
See alsoaddWidget(),removeWidget(), andsetCurrentWidget().
[virtual]QLayoutItem * QStackedLayout::itemAt(int index) constReimplemented fromQLayout::itemAt().
[virtual]QSize QStackedLayout::minimumSize() constReimplemented fromQLayoutItem::minimumSize().
[slot]void QStackedLayout::setCurrentWidget(QWidget * widget)Sets the current widget to be the specifiedwidget. The new current widget must already be contained in this stacked layout.
See alsosetCurrentIndex() andcurrentWidget().
[virtual]void QStackedLayout::setGeometry(constQRect & rect)Reimplemented fromQLayoutItem::setGeometry().
[virtual]QSize QStackedLayout::sizeHint() constReimplemented fromQLayoutItem::sizeHint().
[virtual]QLayoutItem * QStackedLayout::takeAt(int index)Reimplemented fromQLayout::takeAt().
Returns the widget at the givenindex, or 0 if there is no widget at the given position.
See alsocurrentWidget() andindexOf().
[signal]void QStackedLayout::widgetRemoved(int index)This signal is emitted whenever a widget is removed from the layout. The widget'sindex is passed as parameter.
See alsoremoveWidget().
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.