【QML】动画模拟下雪

import QtQuick
import QtQuick.Window
import QtQuick.Controls

Window {
    id: win
    width: 890
    height: 500
    visible: true

    Image {
        id: img
        source: "qrc:/marrychrismas.jpeg"
        fillMode: Image.PreserveAspectFit
    }

    Component {
        id: snowCom
        Image {
            id: sonw
            source: "qrc:/snow.png"
            width: 50
            height: 50
            x: Math.random()*win.width
            y: -sonw.height

            NumberAnimation on y{
                id: anim
                loops: Animation.Infinite
                from: -sonw.height
                to: win.height
                duration: 5000
                easing.type: Easing.InOutQuad
                running: false
            }

            Timer {
                interval: Math.random()*10000
                repeat: false
                running: true
                onTriggered: {
                    anim.running = true
                }
            }
        }
    }

    Repeater {
        model: 50
        delegate: Component {
            Loader {
                property int modelIndex: index
                sourceComponent: snowCom
            }
        }
    }
}

【QML】动画模拟下雪_第1张图片【QML】动画模拟下雪_第2张图片

你可能感兴趣的:(qt6.3,qml,qt)