在 QML 中创建不透明动画

Create an opacity animation in QML

我有一个不透明度为 90% 的灰色矩形,我正在尝试使用动画更改此不透明度。我试过使用 OpacityAnimator,但正如文档所述,Item::opacity 的值在动画完成后更新

这不是我所期望的,我想在动画期间降低不透明度,而不是在 2 秒后立即将其从 90 更改为 0。

这就是我所拥有的:

ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: qsTr("title")
    Rectangle{
        width: parent.width
        height: parent.height
        opacity: 90
        color: "gray"
        id: recLoading
        Text {
            id: txtLoading
            text: qsTr("Loading")
            font.bold: true
        }

        OpacityAnimator on opacity{
            from: 90
            to:0
            duration:2000
            target: parent
            running:true
        }

    }
}

尝试将不透明度值更改为 0 到 1 之间的值,即

...
Rectangle{
    width: parent.width
    height: parent.height
    opacity: 0.9
    ...

OpacityAnimator on opacity{
    from: 0.9
    to: 0.0
    duration:2000
    target: parent
    running:true
}

不透明度指定为 0.0(完全透明)和 1.0(完全不透明)之间的数字。

http://doc.qt.io/qt-5/qml-qtquick-item.html#opacity-prop