QStackedLayout Class Reference

The QStackedLayout class provides a stack of widgets where only one widget is visible at a time.

  1. #include <QStackedLayout>

Inherits: QLayout.

Detailed Description

The QStackedLayout 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 by QTabWidget. There is also a convenience QStackedWidget class built on top of QStackedLayout.

A QStackedLayout can be populated with a number of child widgets ("pages"). For example:

  1.     QWidget *firstPageWidget = new QWidget;
  2.     QWidget *secondPageWidget = new QWidget;
  3.     QWidget *thirdPageWidget = new QWidget;
  4.  
  5.     QStackedLayout *stackedLayout = new QStackedLayout;
  6.     stackedLayout->addWidget(firstPageWidget);
  7.     stackedLayout->addWidget(secondPageWidget);
  8.     stackedLayout->addWidget(thirdPageWidget);
  9.  
  10.     QVBoxLayout *mainLayout = new QVBoxLayout;
  11.     mainLayout->addLayout(stackedLayout);
  12.     setLayout(mainLayout);

QStackedLayout provides no intrinsic means for the user to switch page. This is typically done through a QComboBox or a QListWidget that stores the titles of the QStackedLayout's pages. For example:

  1.     QComboBox *pageComboBox = new QComboBox;
  2.     pageComboBox->addItem(tr("Page 1"));
  3.     pageComboBox->addItem(tr("Page 2"));
  4.     pageComboBox->addItem(tr("Page 3"));
  5.     connect(pageComboBox, SIGNAL(activated(int)),
  6.             stackedLayout, SLOT(setCurrentIndex(int)));

When populating a layout, the widgets are added to an internal list. The indexOf() function returns the index of a widget in that list. The widgets can either be added to the end of the list using the addWidget() function, or inserted at a given index using the insertWidget() function. The removeWidget() function removes the widget at the given index from the layout. The number of widgets contained in the layout, can be obtained using the count() function.

The widget() function returns the widget at a given index position. The index of the widget that is shown on screen is given by currentIndex() and can be changed using setCurrentIndex(). In a similar manner, the currently shown widget can be retrieved using the currentWidget() function, and altered using the setCurrentWidget() function.

Whenever the current widget in the layout changes or a widget is removed from the layout, the currentChanged() and widgetRemoved() signals are emitted respectively.

See also QStackedWidget and QTabWidget.

Public Types

Toggle detailsenum QStackedLayout::

StackingModeStackingMode { StackOne , StackAll 1 ...} { StackOne , StackAll 1 }

This enum specifies how the layout handles its child widgets regarding their visibility.

ConstantValueDescription
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.

Look up this member in the source code.

    Properties

    Toggle detailscountcount : const int

    This property holds the number of widgets contained in the layout

    See also currentIndex() and widget().

    Access functions:

      Look up this member in the source code.

      Toggle detailscurrentIndexcurrentIndex : int

      This property holds the index position of the widget that is visible

      The current index is -1 if there is no current widget.

      See also currentWidget() and indexOf().

      Access functions:

      Look up this member in the source code.

      Toggle detailsstackingModestackingMode : StackingMode

      This property holds determines the way visibility of child widgets are handled.

      The default value is StackOne. Setting the property to StackAll allows you to make use of the layout for overlay widgets that do additional drawing on top of other widgets, for example, graphical editors.

      Access functions:

      Look up this member in the source code.

        Public Functions

        Toggle details QStackedLayout

        QStackedLayoutQStackedLayout () ()

        Constructs a QStackedLayout with no parent.

        This QStackedLayout must be installed on a widget later on to become effective.

        See also addWidget() and insertWidget().

        Look up this member in the source code.

        Toggle details QStackedLayout

        QStackedLayoutQStackedLayout ( QWidget *parent ) ( QWidget *parent )

        Constructs a new QStackedLayout with the given parent.

        This layout will install itself on the parent widget and manage the geometry of its children.

        Look up this member in the source code.

        Toggle details QStackedLayout

        QStackedLayoutQStackedLayout ( QLayout *parentLayout ) ( QLayout *parentLayout )

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

        Look up this member in the source code.

        Toggle details QStackedLayout

        ~QStackedLayout~QStackedLayout () ()

        Destroys this QStackedLayout. Note that the layout's widgets are not destroyed.

        Look up this member in the source code.

        Toggle details void QStackedLayout

        addItemaddItem ( QLayoutItem *item ) ( QLayoutItem *item ) [virtual]

        Reimplemented from QLayout::addItem().

        Look up this member in the source code.

        Toggle details int QStackedLayout

        addWidgetaddWidget ( QWidget *widget ) ( QWidget *widget )

        Adds the given widget to the end of this layout and returns the index position of the widget.

        If the QStackedLayout is empty before this function is called, the given widget becomes the current widget.

        See also insertWidget(), removeWidget(), and setCurrentWidget().

        Look up this member in the source code.

        Toggle details QWidget * QStackedLayout

        currentWidgetcurrentWidget () ()const

        Returns the current widget, or 0 if there are no widgets in this layout.

        See also currentIndex() and setCurrentWidget().

        Look up this member in the source code.

        Toggle details int QStackedLayout

        insertWidgetinsertWidget ( int index , QWidget *widget ) ( int index , QWidget *widget )

        Inserts the given widget at the given index in this QStackedLayout. If index is out of range, the widget is appended (in which case it is the actual index of the widget that is returned).

        If the QStackedLayout is empty before this function is called, the given widget 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 also addWidget(), removeWidget(), and setCurrentWidget().

        Look up this member in the source code.

        Toggle details QLayoutItem * QStackedLayout

        itemAtitemAt ( int index ) ( int index )const [virtual]

        Reimplemented from QLayout::itemAt().

        Look up this member in the source code.

        Toggle details QSize QStackedLayout

        minimumSizeminimumSize () ()const [virtual]

        Reimplemented from QLayoutItem::minimumSize().

        Look up this member in the source code.

        Toggle details void QStackedLayout

        setGeometrysetGeometry ( const QRect &rect ) ( const QRect &rect ) [virtual]

        Reimplemented from QLayoutItem::setGeometry().

        Look up this member in the source code.

        Toggle details QSize QStackedLayout

        sizeHintsizeHint () ()const [virtual]

        Reimplemented from QLayoutItem::sizeHint().

        Look up this member in the source code.

        Toggle details QLayoutItem * QStackedLayout

        takeAttakeAt ( int index ) ( int index ) [virtual]

        Reimplemented from QLayout::takeAt().

        Look up this member in the source code.

        Toggle details QWidget * QStackedLayout

        widgetwidget ( int index ) ( int index )const

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

        See also currentWidget() and indexOf().

        Look up this member in the source code.

          Signals

          Toggle details void QStackedLayout

          currentChangedcurrentChanged ( int index ) ( int index ) [signal]

          This signal is emitted whenever the current widget in the layout changes. The index specifies 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 QStackedLayout)

          See also currentWidget() and setCurrentWidget().

          Look up this member in the source code.

          Toggle details void QStackedLayout

          widgetRemovedwidgetRemoved ( int index ) ( int index ) [signal]

          This signal is emitted whenever a widget is removed from the layout. The widget's index is passed as parameter.

          See also removeWidget().

          Look up this member in the source code.

            Public Slots

            Toggle details void QStackedLayout

            setCurrentWidgetsetCurrentWidget ( QWidget *widget ) ( QWidget *widget ) [slot]

            Sets the current widget to be the specified widget. The new current widget must already be contained in this stacked layout.

            See also setCurrentIndex() and currentWidget().

            Look up this member in the source code.

              Notes provided by the Qt Community

              No notes