QML —— ProgressBar示例(附完整源码)

示例 - 效果

在这里插入图片描述

实例 - 源码
import QtQuick 2.12
import QtQuick.Window 2.12

import QtQuick.Layouts 1.12
import QtQuick.Controls 2.5

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

    Column
    {
   
        spacing: 40
        anchors.centerIn: parent

        Row
        {
   
            spacing: 20
            Text
            {
   
                text: qsTr("ProgressBar类型1:")
                font.family: "微软雅黑"
                font.pixelSize: 18
            }
            ProgressBar
            {
   
                id: pb1
                value: 0.0
                anchors.verticalCenter: parent.verticalCenter
            }
            Text
            {
   
                text: qsTr("小球当前角度:")
                anchors.verticalCenter: parent.verticalCenter
            }
            Text
            {
   
                id: pb1Value
                width: 80
                text: qsTr("--")
                anchors.verticalCenter: parent.verticalCenter
            }
        }

        Row
        {
   
            spacing: 20
            Text
            {
   
                text: qsTr("ProgressBar类型2:")
                font.family: "微软雅黑"
                font.pixelSize: 18
            }
            ProgressBar
            {
   
                id: pb2
                indeterminate: false
                anchors.verticalCenter: parent.verticalCenter
            }
            Text
            {
   
                text: qsTr("小球当前角度:")
                anchors.verticalCenter: parent.verticalCenter
            }
            Text
            {
   
                id: pb2Value
                width: 80
                text: qsTr("--")
                anchors.verticalCenter: parent.verticalCenter
            }
        }


        Timer
        {
   
            id: _timer
            interval: 100
            repeat: true
            triggeredOnStart: false
            running: false

            onTriggered:
            {
   
                let rotationValue = imgId.rotation / 360
                pb1.value = rotationValue
                if(rotationValue === 1.0)
                {
   
                    running = false
                    pb2.indeterminate = false
                    pb2.value = rotationValue
                }
                else
                {
   
                    pb2.indeterminate = true
                }

                pb1Value.text = pb2Value.text = Math.floor(imgId.rotation)
            }
        }

        Image
        {
   
            id: imgId
            height: 140
            width: 140
            source: "qrc:/ball.jpeg"
            anchors.horizontalCenter: parent.horizontalCenter

            NumberAnimation on rotation
            {
   
                id: imgAnimationId
                from: 0
                to:360
                duration: 6000
                running: false
                easing.type: Easing.Linear
            }
        }

        Button
        {
   
            anchors.horizontalCenter: parent.horizontalCenter
            text: qsTr("开始(6秒转球360°)")

            onClicked:
            {
   
                let txt = text;
                if(txt.indexOf("开始") !== -1)
                {
   
                    _timer.start()
                    imgAnimationId.start()
                    text = qsTr("停止")
                }
                else
                {
   
                    _timer.stop()
                    imgAnimationId.stop()
                    text = qsTr("开始(10秒转球360°)")
                }
            }
        }

    }
}

关注

笔者 - jxd

相关推荐

  1. QML —— 使用Qt虚拟键盘示例完整

    2023-12-28 16:50:02       68 阅读

最近更新

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

    2023-12-28 16:50:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-28 16:50:02       100 阅读
  3. 在Django里面运行非项目文件

    2023-12-28 16:50:02       82 阅读
  4. Python语言-面向对象

    2023-12-28 16:50:02       91 阅读

热门阅读

  1. 2974. 最小数字游戏 23.12.23(二)

    2023-12-28 16:50:02       51 阅读
  2. 力扣面试经典题之哈希表

    2023-12-28 16:50:02       66 阅读
  3. Leetcod面试经典150题刷题记录 —— 区间篇

    2023-12-28 16:50:02       58 阅读
  4. js如何判断一个字符串是否为json格式

    2023-12-28 16:50:02       58 阅读
  5. 使用Aspose.Words合并表格的单元格

    2023-12-28 16:50:02       49 阅读
  6. 知识笔记(五十九)———css 美化滚动条样式

    2023-12-28 16:50:02       56 阅读
  7. 【CSS】布局方式梳理和总结

    2023-12-28 16:50:02       46 阅读
  8. Golang学习之路一三基本数据类型

    2023-12-28 16:50:02       54 阅读
  9. Ubuntu安装MongoDB

    2023-12-28 16:50:02       62 阅读
  10. Sass(Scss)、Less的区别与选择 + 基本使用

    2023-12-28 16:50:02       57 阅读
  11. Mysql中 distinct 和 group by 哪个效率高?

    2023-12-28 16:50:02       57 阅读