6.0.0-rc4Source

QStackedLayout Class

The QStackedLayout class lays out widgets so that only one of them is visible at a time. More…

Header#include <QStackedLayout>
CMaketarget_link_libraries(app PRIVATE Nt::Widgets)
ModuleNt Widgets C++ Classes
InheritsQLayout

List of all members, including inherited members

Public Functions

QStackedLayout(QWidget *parent = nullptr)
~QStackedLayout()
intaddWidget(QWidget *widget)
intinsertWidget(int index, QWidget *widget)
QWidget *widget(int index) const
QWidget *currentWidget() const
intcurrentIndex() const

Reimplemented Public Functions

voidaddItem(QLayoutItem *item)
QLayoutItem *itemAt(int index) const
QLayoutItem *takeAt(int index)
QSizesizeHint() const
QSizeminimumSize() const
Qt::OrientationsexpandingDirections() const
voidsetGeometry(const QRect &rect)

Public Slots

voidsetCurrentIndex(int index)
voidsetCurrentWidget(QWidget *widget)

Signals

voidcurrentChanged(int index)
voidwidgetRemoved(int index)

Detailed Description

All the widgets of a stacked layout have the size of the layout, and the current one is shown while the others are hidden. A QStackedWidget has one of these, and a QComboBox or a list can choose the page:

QStackedLayout *pages = new QStackedLayout(window);
pages->addWidget(generalPage);
pages->addWidget(advancedPage);
connect(combo, &QComboBox::currentIndexChanged, pages, &QStackedLayout::setCurrentIndex);

The size hint of the layout is the largest hint of its widgets, so the window has room for any page.

See also QStackedWidget, QTabWidget and QLayout.

Differences from Qt

There is no stackingMode(): only the current widget is shown, as in Qt's default StackOne. A stacked layout can only hold widgets: addItem() takes the widget of the item. It has no contents margins by default.

Member Function Documentation

[explicit] QStackedLayout::QStackedLayout(QWidget *parent = nullptr)

Constructs a stacked layout for parent, with no widgets.

[override] QStackedLayout::~QStackedLayout()

Destroys the layout. The widgets that are in it stay.

[override] void QStackedLayout::addItem(QLayoutItem *item)

Reimplements QLayout::addItem().

A stacked layout holds widgets only: the widget of item is added, and item is deleted. An item that is not a widget is ignored.

int QStackedLayout::addWidget(QWidget *widget)

Adds widget at the end of the layout and returns its index. If it is the first widget, it becomes the current one.

See also insertWidget().

[signal] void QStackedLayout::currentChanged(int index)

This signal is emitted when the current widget changes, with its index, or -1 if there is none.

int QStackedLayout::currentIndex() const

Returns the index of the current widget, or -1 if there is none.

See also setCurrentIndex().

QWidget * QStackedLayout::currentWidget() const

Returns the current widget, or nullptr if there is none.

See also currentIndex().

[override] Qt::Orientations QStackedLayout::expandingDirections() const

Reimplements QLayout::expandingDirections().

int QStackedLayout::insertWidget(int index, QWidget *widget)

Inserts widget at index, which is brought into the range 0 to count(), and returns the index it got. It becomes the current widget if there is none; otherwise it is hidden. The layout makes it a child of the widget it manages.

See also addWidget().

[override] QLayoutItem * QStackedLayout::itemAt(int index) const

Reimplements QLayout::itemAt().

[override] QSize QStackedLayout::minimumSize() const

Reimplements QLayout::minimumSize().

[slot] void QStackedLayout::setCurrentIndex(int index)

Makes the widget at index the current one: it is shown and the one before is hidden. Does nothing if there is no widget at index. Emits currentChanged().

See also currentIndex().

[slot] void QStackedLayout::setCurrentWidget(QWidget *widget)

Makes widget the current one. Does nothing if it is not in the layout.

See also setCurrentIndex().

[override] void QStackedLayout::setGeometry(const QRect &rect)

Reimplements QLayout::setGeometry().

Gives the current widget the whole rectangle, within the margins.

[override] QSize QStackedLayout::sizeHint() const

Reimplements QLayout::sizeHint().

[override] QLayoutItem * QStackedLayout::takeAt(int index)

Reimplements QLayout::takeAt().

If the widget was the current one, the next widget becomes the current one, or the one before if it was the last. Emits widgetRemoved(), and currentChanged() if the current widget was the one removed.

QWidget * QStackedLayout::widget(int index) const

Returns the widget at index, or nullptr if there is none.

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

This signal is emitted when the widget that was at index is removed from the layout.