导入模块
import QtQuick.Layouts 1.15 //注意
继承
item类
属性
count
设置布局的项数量。
currentIndex
设置当前可见项的索引。
附加属性(好像无效)
StackLayout.index
这个附加的属性包含StackLayout中每个子项目的索引。需导入 QtQuick.Layouts 1.15
StackLayout.isCurrentItem
如果该子元素是StackLayout中的当前项,则此附加属性为真。需导入 QtQuick.Layouts 1.15
StackLayout.layout
这个附加的属性包含了管理子项目的StackLayout。需导入 QtQuick.Layouts 1.15
布局中的项支持以下附加属性
Layout.minimumWidth
Layout.minimumHeight
Layout.preferredWidth
Layout.preferredHeight
Layout.maximumWidth
Layout.maximumHeight
Layout.fillWidth
Layout.fillHeight
以上同其他布局的通用属性。可参考:QML 布局:列布局(ColumnLayout)和行布局(RowLayout )
举例
StackLayout {
id: layout
anchors.fill: parent
currentIndex: 1
Rectangle {
color: 'teal'
implicitWidth: 200
implicitHeight: 200
}
Rectangle {
color: 'plum'
implicitWidth: 300
implicitHeight: 200
}
}
官方文档:https://doc.qt.io/qt-6/qml-qtquick-layouts-stacklayout.html#index-attached-prop