QML transition 立即改变,不根据'duration'

QML transition changes immediately, not according to 'duration'

我有以下 QML 文件。当单击 root 项时,我不想让矩形 myRect 从右侧滑入(简化设置)。实际发生的是 myRect 在单击 root 项时立即出现。

我检查了 运行 属性 的过渡,这似乎没问题。当我单击 root 项时,它会记录 true,然后在 2 秒后记录 false

有谁知道为什么 x 属性 不逐渐改变?

import QtQuick 2.7

Item{
    id: root

    MouseArea{
        anchors.fill: parent
        onClicked: {
            myRect.state = "visible"
        }
    }          

    Rectangle{
        id: myRect

        width: root.width
        height: root.height

        state: "hidden"

        color: "yellow"

        states: [
            State {
                name: "hidden"
                PropertyChanges{
                    target: myRect
                    x: myRect.width
                }
            },
            State {
                name: "visible"
                PropertyChanges{
                    target: myRect
                    x: 0
                }
            }                
        ]
        transitions: [
            Transition {
                NumberAnimation{
                    duration: 2000
                }
                onRunningChanged: {
                    console.log("Running:", running)
                }
            }
        ]
    }
}

您必须指明 属性,在您的情况下 "x"

NumberAnimation{
    duration: 2000
    properties: "x"
}