【QML】动画模拟下雪

发布时间:2023年12月20日

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

文章来源:https://blog.csdn.net/wangyi463295828/article/details/135035676
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。