StackView:类似于栈的视图
演示代码:
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.2
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
StackView{ //类似于栈的结构,最后进栈的视图在最上面显示,下面的视图被上面的视图覆盖不显示
id: stackView
anchors.fill: parent
initialItem: com //初始化的组件 等价于Component.onCompleted:stackView.push(com)
Component{
id:com
Rectangle{
width: 100
height: 100
color: "red"
}
}
}
Component.onCompleted: {
stackView.push(com,{"color":"blue"}) ///将组件进栈
stackView.push(com,{"color":"red"})
stackView.push(com,{"color":"green"})
stackView.push(com,{"color":"black"}) //最后将显示黑色
}
}
效果如下: