Qt/QML学习-ProgressBar

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")

    ProgressBar {
        id: progressBar
        width: 300
        height: 20
        anchors.centerIn: parent
        from: 0
        to: 100
        value: 50
        // 显示进度过程动画,不显示具体进度
        indeterminate: checkBox.checked
        background: Rectangle {
            color: "yellow"
            border.width: 1
        }
        contentItem: Item {
            // 利用from、to、value绘制进度
            Rectangle {
                id: rect
                width: parent.width / 20
                height: parent.height - 10
                y: 5
                color: "red"
                property real indeterminateX: 0
                x: progressBar.indeterminate? indeterminateX
                   : parent.width
                   / (progressBar.to - progressBar.from)
                   * (progressBar.value - progressBar.from)
                   - width / 2
                Timer {
                    interval: 10
                    repeat: true
                    running: progressBar.indeterminate
                    onTriggered: {
                        rect.indeterminateX += progressBar.width / 100
                        if (rect.indeterminateX >= (progressBar.width - rect.width)) {
                            rect.indeterminateX = 0
                        }
                    }
                }
            }
        }
    }

    CheckBox {
        id: checkBox
        anchors.bottom: progressBar.top
        anchors.left: progressBar.left
    }

    TextInput {
        id: textInput
        anchors.bottom: progressBar.top
        anchors.left: checkBox.right
        font.pointSize: 30
        onEditingFinished: {
            progressBar.value = text
        }
    }

    Component.onCompleted: {
        textInput.text = progressBar.value
    }
}

演示

视频讲解

相关推荐
知识分享小能手1 小时前
jQuery 入门学习教程,从入门到精通, jQuery在HTML5中的应用(16)
前端·javascript·学习·ui·jquery·html5·1024程序员节
吃个糖糖1 小时前
Pytorch 学习之Transforms
人工智能·pytorch·学习
常常不爱学习1 小时前
Vue3 + TypeScript学习
开发语言·css·学习·typescript·html
CandyU22 小时前
UE5 C++ 进阶学习 小知识点 —— 01 - 本地化语言
学习·ue5
老歌老听老掉牙2 小时前
解决 PyQt5 中 sipPyTypeDict() 弃用警告的完整指南
python·qt
武陵悭臾2 小时前
Python应用开发学习: Pygame 中实现数字水平靠右对齐和垂直靠底对齐
python·学习·程序人生·游戏·个人开发·学习方法·pygame
Tonya432 小时前
测开学习DAY26
学习
水月wwww3 小时前
vue学习之组件与标签
前端·javascript·vue.js·学习·vue
952363 小时前
数据结构-链表
java·数据结构·学习
找了一圈尾巴4 小时前
软件架构设计学习-基本概念
学习·软件架构