源码是这样的:
import QtQuick 2.12
import QtQuick.Window 2.12
//import QtQuick.Controls 1.4
import QtQuick.Controls 2.12
Window {
id: root
visible: true
width: 640
height: 480
title: qsTr("Hello World")
color: "black"
Component {
id: page_1
Item {
id: page_1_item
Rectangle{
id: rect1;
anchors.fill: parent
color: "red"
}
}
}
Component {
id: page_2
Item {
id: page_2_item
Rectangle{
id: rect2;
anchors.fill: parent
color: "yellow"
}
}
}
StackView {
anchors.fill: parent
id: mystackview
initialItem: page_1
pushEnter: Transition {
PropertyAnimation {
target: page_2_item
property: "y"
from: -root.height
to: 0
duration: 300
}
}
pushExit: Transition {
PropertyAnimation {
target: page_1_item
property: "y"
from: 0
to: root.height
duration: 300
}
}
popEnter: Transition {
PropertyAnimation {
target: page_1_item
property: "y"
from: -root.height
to: 0
duration: 300
}
}
popExit: Transition {
PropertyAnimation {
target: page_2_item
property: "y"
from: 0
to: root.height
duration: 300
}
}
Component.onCompleted: {
// mystackview.push(page_1);
// mystackview.push(page_2);
console.log(mystackview.depth);
}
MouseArea {
anchors.fill: parent;
// mystackview.push(page_2);
onClicked: {
console.log("=======================================");
if(mystackview.depth < 2)mystackview.push(page_2);
else mystackview.pop(1);
console.log(mystackview.depth,mystackview.currentItem);
//if(stack.depth == 0)stack.push(page);
}
}
}
}
软件实现的过渡效果没问题但是第一次点击会报错:
|