找回密码
 立即注册
收起左侧

stackview过渡动画报错

0
回复
3461
查看
[复制链接]
累计签到:3 天
连续签到:1 天
来源: 2022-2-16 18:11:25 显示全部楼层 |阅读模式
1Qter豆
源码是这样的:

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);
        }
    }

}

}



软件实现的过渡效果没问题但是第一次点击会报错:

附件: 您需要 登录 才可以下载或查看,没有帐号?立即注册
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了