StackView管理着view页面的生命周期,提供了页面的栈式导航。这些view页面可能有业务需要,根据业务需要,可以一级一级向深处跳转,根据当前view的状态与设定的情况,可能产生一个新view或者返回之前view
比如:注册账号分步骤,输入用户名,密码,点击下一步之后,出现新页面,输入兴趣爱好等
//定义一个StackView
ApplicationWindow{ title:"StckViewDemo" visible:true height:300 width:530 StackView { id:stack; anchors.fill:parent width:600 height:300 property var home :null; Text { text:"Cloxk to create first page" font.pointSize: 14 font.bold: true color: "blue" anchors.centerIn: parent MouseArea{ anchors.fill: parent onClicked: if(stack.depth==0) stack.push(page); } } } Component { id: page Rectangle { color: Qt.rgba(stack.depth*0.1,stack.depth*0.2,stack.depth*0.3); Text { anchors.centerIn: parent; text: "depth-"+stack.depth; font.pointSize: 24; font.bold: true color: stack.depth<=4?Qt.lighter(parent.color):Qt.darker(parent.color); } Button{ id:next; anchors.right: parent.right; anchors.bottom: parent.bottom; anchors.margins: 8; text:"Next" width:70 height: 30; onClicked: { if(stack.depth<8) stack.push(page); } } Button{ id:back; anchors.right: next.left; anchors.top: next.top; anchors.rightMargin: 8; text:"Back" width:70 height: 30; onClicked: { if(stack.depth>0) stack.pop(); } } Button{ id:home; anchors.right: back.left; anchors.top: next.top; anchors.rightMargin: 8; text:"Home" width:70 height: 30; onClicked: { if(stack.depth>0) stack.pop(stack.initialItem); } } Button{ id:clear; anchors.right: home.left; anchors.top: next.top; anchors.rightMargin: 8; text:"Clear" width:70 height: 30; onClicked: { if(stack.depth>0) stack.clear(); } } } } }