StackLayout QML Type

StackLayout 类提供了一个项目堆栈,一次只能显示一个项目。更多

Import Statement: import QtQuick.Layouts
Inherits:

Item

属性

附属物业

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

详细说明

为了更有效地使用该类型,建议您了解Qt Quick Layouts 模块的一般机制。更多信息请参阅Qt Quick Layouts Overview

可以通过设置currentIndex 属性来修改当前可见项。索引与堆栈布局子项的顺序相对应。

与大多数其他布局不同,子项的Layout.fillWidthLayout.fillHeight 属性默认为true 。因此,只要子项目的Layout.maximumWidthLayout.maximumHeight 不阻止填充,子项目就会默认按照堆栈布局的大小进行填充。

通过将项目重新代理到布局,可以将项目添加到布局中。同样,将项目从布局中移除也是通过将项目重新代理到布局中来完成的。这两种操作都会影响布局的count 属性。

下面的代码将创建一个堆栈布局,其中只有 "梅花 "矩形是可见的。

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

堆栈布局中的项目支持这些附加属性:

在此阅读有关附加属性的更多信息。

另请参阅 ColumnLayout,GridLayout,RowLayout,StackViewQt Quick 布局概述

属性文档

count : int [read-only]

该属性表示属于布局的项的数量。

只有作为StackLayout 的子项的项目才是布局的候选项。


currentIndex : int

该属性保存当前在StackLayout 中可见的子项的索引。默认情况下,对于空布局,该索引为-1 ,否则默认为0 (指第一个项)。

自 6.5 版起,在索引小于或等于当前索引的位置插入/移除新项时,将增加/减少当前索引,但保留当前项。


附加属性文档

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

该附加属性保存StackLayout 中每个子项的索引。

该属性在 QtQuick.Layouts 1.15 中引入。

另请参阅 isCurrentItemlayout


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

如果该子项目是StackLayout 中的当前项目,则该 attached 属性为true

该属性在 QtQuick.Layouts 1.15 中引入。

另请参阅 indexlayout


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

此attached属性保存管理此子项的StackLayout

该属性在 QtQuick.Layouts 1.15 中引入。

另请参阅 indexisCurrentItem


© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.