StackLayout QML Type

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

import 语句: import QtQuick.Layouts 1.3
继承: Item

特性

详细描述

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 特性。

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:

Read more about attached properties here .

另请参阅 ColumnLayout , GridLayout , RowLayout ,和 StackView .

特性文档编制

count : int

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