QProgressBar

71 篇文章 4 订阅

QProgressBar

1.进度条
2.功能类似QSlider

QDialog 示例
1.加载进度显示

QDialog渐变透明关闭窗口
1.10 0.0 setWindowOpacity
2.QEventLoop loop;
3.loop.processEvents();

ui_progressdialog.h


#ifndef UI_PROGRESSDIALOG_H
#define UI_PROGRESSDIALOG_H

#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QDialog>
#include <QtWidgets/QLabel>
#include <QtWidgets/QProgressBar>
#include <QtWidgets/QWidget>

QT_BEGIN_NAMESPACE

class Ui_ProgressDialog
{
public:
    QWidget *widget;
    QProgressBar *progressBar;
    QLabel *label;

    void setupUi(QDialog *ProgressDialog)
    {
        if (ProgressDialog->objectName().isEmpty())
            ProgressDialog->setObjectName(QString::fromUtf8("ProgressDialog"));
        ProgressDialog->resize(700, 200);
        ProgressDialog->setStyleSheet(QString::fromUtf8("#widget{\n"
"   background-color: qlineargradient(spread:reflect, x1:1, y1:0.533, x2:1, y2:1, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));\n"
"   border:1px groove rgb(232,232,232);\n"
"   border-radius:20;\n"
"}"));
        widget = new QWidget(ProgressDialog);
        widget->setObjectName(QString::fromUtf8("widget"));
        widget->setGeometry(QRect(0, 0, 700, 200));
        widget->setStyleSheet(QString::fromUtf8(""));
        progressBar = new QProgressBar(widget);
        progressBar->setObjectName(QString::fromUtf8("progressBar"));
        progressBar->setGeometry(QRect(40, 40, 601, 121));
        progressBar->setMaximum(1000);
        progressBar->setValue(24);
        label = new QLabel(widget);
        label->setObjectName(QString::fromUtf8("label"));
        label->setGeometry(QRect(320, -3, 67, 40));

        retranslateUi(ProgressDialog);

        QMetaObject::connectSlotsByName(ProgressDialog);
    } // setupUi

    void retranslateUi(QDialog *ProgressDialog)
    {
        ProgressDialog->setWindowTitle(QCoreApplication::translate("ProgressDialog", "ProgressDialog", nullptr));
        label->setText(QCoreApplication::translate("ProgressDialog", "TextLabel", nullptr));
    } // retranslateUi

};

namespace Ui {
    class ProgressDialog: public Ui_ProgressDialog {};
} // namespace Ui

QT_END_NAMESPACE

#endif // UI_PROGRESSDIALOG_H


progressdialog.cpp


#include "progressdialog.h"
#include "ui_progressdialog.h"


ProgressDialog::ProgressDialog(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::ProgressDialog)
{
    ui->setupUi(this);
    //去掉标题栏
    this->setWindowFlags(Qt::FramelessWindowHint);

    //设置背景透明
    this->setAttribute(Qt::WA_TranslucentBackground,true);
}

void ProgressDialog::SetPos(int pos)
{
    ui->progressBar->setValue(pos);
    if(pos == 1000)
    {
        for(int i = 100; i > 0; i--)
        {
            //透明度1.0 0.0
            double value = (double)i / 100.0;
            qDebug()<<value;
            this->setWindowOpacity(value);
            QThread::msleep(30);
            ui->label->setText(QString::number(i));
            QEventLoop loop;
            loop.processEvents();
        }
        this->close();
    }
}


ProgressDialog::~ProgressDialog()
{
    delete ui;
}

TestPro.cpp


#include "TestPro.h"

TestPro::TestPro()
    :QThread()
{

}

TestPro::~TestPro()
{

}

void TestPro::run()
{
    //模拟
    for(int i = 0; i <= 1000; i++)
    {
        SetPos(i);
        msleep(10);
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值