Qt/QML学习-BusyIndicator

QML学习

main.qml

import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")

    BusyIndicator {
        id: busyIndicator
        anchors.fill: parent
        MouseArea {
            anchors.fill: parent
            onClicked: {
                busyIndicator.running = busyIndicator.running? false: true
            }
        }

        background: Rectangle {
            id: backgroundRect
            color: "transparent"
        }

        contentItem: Item {
            Rectangle {
                anchors.centerIn: parent
                width: parent.width < parent.height? parent.width / 4 * 3: parent.height / 4 * 3
                height: width
                color: backgroundRect.color
                radius: height / 2
                border.width: height / 12
            }

            Canvas {
                id: canvas
                anchors.centerIn: parent
                width: parent.width < parent.height? parent.width / 4 * 3: parent.height / 4 * 3
                height: width
                property real angle: 0
                onPaint: {
                    rotate()
                }
                function rotate() {
                    var ctx = getContext('2d')
                    ctx.clearRect(0, 0, canvas.width, canvas.height)
                    ctx.beginPath()
                    ctx.arc(width/2, height/2, height/2-height/12/2, canvas.angle, canvas.angle + Math.PI * 2 / 12, false)
                    ctx.lineWidth = height / 12
                    ctx.strokeStyle = "red"
                    ctx.stroke()
                    requestAnimationFrame(rotate)
                }
                Timer {
                    repeat: true
                    interval: 25
                    onTriggered: {
                        canvas.angle += Math.PI * 2 / 24
                    }
                    running: busyIndicator.running
                }
            }
        }
    }
}

演示

相关推荐

  1. Qt/QML学习-BusyIndicator

    2024-07-14 05:32:05       22 阅读
  2. 学习 学习

    2024-07-14 05:32:05       61 阅读
  3. 学期学习计划

    2024-07-14 05:32:05       40 阅读
  4. 学习笔记:机器学习

    2024-07-14 05:32:05       76 阅读

最近更新

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

    2024-07-14 05:32:05       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-14 05:32:05       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-14 05:32:05       58 阅读
  4. Python语言-面向对象

    2024-07-14 05:32:05       69 阅读

热门阅读

  1. 算法热门面试题二

    2024-07-14 05:32:05       28 阅读
  2. pyinstaller系列教程(一)-基础介绍

    2024-07-14 05:32:05       20 阅读
  3. 大语言模型系列-Transformer

    2024-07-14 05:32:05       25 阅读
  4. Layer2是什么?为什么需要Layer2?

    2024-07-14 05:32:05       25 阅读
  5. SpinalHDL之实用工具(上篇)

    2024-07-14 05:32:05       22 阅读
  6. 自监督学习和对比学习举例讲解(附代码)

    2024-07-14 05:32:05       20 阅读
  7. web黑马课总结笔记(持续更新)

    2024-07-14 05:32:05       24 阅读