【问题标题】:QML transition changes immediately, not according to 'duration'QML 转换立即更改,而不是根据“持续时间”
【发布时间】:2017-11-10 14:22:09
【问题描述】:

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

我检查了过渡的 running 属性,这似乎没问题。当我单击 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)
                }
            }
        ]
    }
}

【问题讨论】:

    标签: qt qml qtquick2 transitions


    【解决方案1】:

    您必须指明属性,在您的情况下为“x”

    NumberAnimation{
        duration: 2000
        properties: "x"
    }
    

    【讨论】:

    • 谢谢,这行得通。我实际上尝试过那个,但忘记了“”
    猜你喜欢
    • 2020-11-08
    • 2021-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-03
    • 1970-01-01
    • 2011-05-09
    • 2011-06-20
    相关资源
    最近更新 更多