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

相关推荐

  1. Qt/QML学习-动画元素

    2023-12-17 16:46:06       23 阅读
  2. QML:Instantiator 动态创建对象的元素

    2023-12-17 16:46:06       48 阅读
  3. QML Controls模块-标准对话框用法说明

    2023-12-17 16:46:06       24 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-17 16:46:06       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-17 16:46:06       101 阅读
  3. 在Django里面运行非项目文件

    2023-12-17 16:46:06       82 阅读
  4. Python语言-面向对象

    2023-12-17 16:46:06       91 阅读

热门阅读

  1. AIGC stable diffusion学习笔记

    2023-12-17 16:46:06       60 阅读
  2. Golang 二分查找 LEETCODE704 小记

    2023-12-17 16:46:06       69 阅读
  3. css前端主题切换方案(三种)

    2023-12-17 16:46:06       49 阅读
  4. C语言经典错误总结(三)

    2023-12-17 16:46:06       57 阅读
  5. 在Flutter中使用PhotoViewGallery指南

    2023-12-17 16:46:06       64 阅读
  6. 【Qt5】QMouseEvent的globalPos

    2023-12-17 16:46:06       56 阅读
  7. Harmonyos系统web组件使用

    2023-12-17 16:46:06       52 阅读
  8. css中定位方式

    2023-12-17 16:46:06       62 阅读
  9. ESlint代码规范

    2023-12-17 16:46:06       56 阅读