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

演示

视频讲解

相关推荐
peace..2 分钟前
温湿度变送器与电脑进行485通讯连接并显示在触摸屏中(mcgs)
经验分享·学习·其他
软件黑马王子1 小时前
C#系统学习第八章——字符串
开发语言·学习·c#
坏柠1 小时前
C++ Qt 基础教程:信号与槽机制详解及 QPushButton 实战
c++·qt
雨落倾城夏未凉2 小时前
4.信号与槽
后端·qt
strongwyy3 小时前
蓝牙墨水屏上位机学习(2)
学习
九皇叔叔3 小时前
(3)手摸手-学习 Vue3 之 变量声明【ref 和 reactive】区别
学习
The_cute_cat5 小时前
Ajax和Axios的初步学习
前端·学习·ajax
amazinging6 小时前
北京-4年功能测试2年空窗-报培训班学测开-第四十三天
python·学习
祁思妙想6 小时前
八股学习(五)---MySQL
学习
虾球xz7 小时前
CppCon 2018 学习:THE MOST VALUABLE VALUES
开发语言·c++·学习