- Qt 6.11
- Qt Quick
- QML Types
- QtQuick.Layouts
- StackLayout
- Qt 6.11.2 Reference Documentation

# StackLayout QML Type

The StackLayout class provides a stack of items where only one item is visible at a time. More...

Import Statement: | `import QtQuick.Layouts`
Inherits: | Item

- List of all members, including inherited members

## Properties

- count : int
- currentIndex : int

## Attached Properties

- index : int `(since QtQuick.Layouts 1.15)`
- isCurrentItem : bool `(since QtQuick.Layouts 1.15)`
- layout : StackLayout `(since QtQuick.Layouts 1.15)`

## Detailed Description

To be able to use this type more efficiently, it is recommended that you understand the general mechanism of the Qt Quick Layouts module. Refer to Qt Quick Layouts Overview for more information.

The current visible item can be modified by setting the currentIndex property. The index corresponds to the order of the StackLayout's children.

In contrast to most other layouts, child Items' Layout.fillWidth and Layout.fillHeight properties default to `true`. As a consequence, child items are by default filled to match the size of the StackLayout as long as their Layout.maximumWidth or Layout.maximumHeight does not prevent it.

Items are added to the layout by reparenting the item to the layout. Similarly, removal is done by reparenting the item from the layout. Both of these operations will affect the layout's count property.

The following code will create a StackLayout where only the 'plum' rectangle is visible.

     StackLayout {
         id: layout
         anchors.fill: parent
         currentIndex: 1
         Rectangle {
             color: 'teal'
             implicitWidth: 200
             implicitHeight: 200
         }
         Rectangle {
             color: 'plum'
             implicitWidth: 300
             implicitHeight: 200
         }
     }

Items in a StackLayout support these attached properties:

- Layout.minimumWidth
- Layout.minimumHeight
- Layout.preferredWidth
- Layout.preferredHeight
- Layout.maximumWidth
- Layout.maximumHeight
- Layout.fillWidth
- Layout.fillHeight

Read more about attached properties here.

See also ColumnLayout, GridLayout, RowLayout, StackView, and Qt Quick Layouts Overview.

## Property Documentation

### count : int `[read-only]`

This property holds the number of items that belong to the layout.

Only items that are children of the StackLayout will be candidates for layouting.

### currentIndex : int

This property holds the index of the child item that is currently visible in the StackLayout. By default it will be `-1` for an empty layout, otherwise the default is `0` (referring to the first item).

Since 6.5, inserting/removing a new Item at an index less than or equal to the current index will increment/decrement the current index, but keep the current Item.

## Attached Property Documentation

### StackLayout.index : int `[read-only, since QtQuick.Layouts 1.15]`

This attached property holds the index of each child item in the StackLayout.

This property was introduced in QtQuick.Layouts 1.15.

See also isCurrentItem and layout.

### StackLayout.isCurrentItem : bool `[read-only, since QtQuick.Layouts 1.15]`

This attached property is `true` if this child is the current item in the StackLayout.

This property was introduced in QtQuick.Layouts 1.15.

See also index and layout.

### StackLayout.layout : StackLayout `[read-only, since QtQuick.Layouts 1.15]`

This attached property holds the StackLayout that manages this child item.

This property was introduced in QtQuick.Layouts 1.15.

See also index and isCurrentItem.