进度条,进度条对话框,QProgressBar类

#include <QWidget>
#include <QLabel>
#include <QLineEdit>
#include <QComboBox>
#include <QProgressBar>
#include <QDialog>
#include <QPushButton>

class Progress : public QDialog
{
    Q_OBJECT

public:
    Progress(QWidget *parent = 0);
    ~Progress();

public slots:
    void startProgress();

private:
    QLabel *fileNum;
    QLineEdit *fileNumEdit;
    QLabel *showType;
    QComboBox *comboBox;

    QProgressBar *progressBar;

    QPushButton *startBtn;
};


#include "widget.h"
#include <QGridLayout>
#include <QProgressDialog>

Progress::Progress(QWidget *parent)
    : QDialog(parent)
{
    fileNum = new QLabel(tr("文件数目:"));
    fileNumEdit = new QLineEdit;

    showType = new QLabel(tr("显示类型:"));
    comboBox = new QComboBox;
    comboBox->addItem(tr("progressBar"));
    comboBox->addItem(tr("progressDialog"));

    progressBar = new QProgressBar;

    startBtn = new QPushButton(tr("开始"));

    QGridLayout *mainLayout = new QGridLayout(this);
    mainLayout->addWidget(fileNum,0,0);
    mainLayout->addWidget(fileNumEdit,0,1);
    mainLayout->addWidget(showType,1,0);
    mainLayout->addWidget(comboBox,1,1);
    mainLayout->addWidget(progressBar,2,0,1,2);
    mainLayout->addWidget(startBtn,3,1);
    mainLayout->setMargin(15);
    mainLayout->setSpacing(10);
    connect(startBtn,SIGNAL(clicked(bool)),this,SLOT(startProgress()));
}

Progress::~Progress()
{

}

void Progress::startProgress()
{
    //文件数目
    int num = fileNumEdit->text().toInt();
    if(comboBox->currentIndex() == 0)
    {
        //设置进度条的范围从0到文件数目
        progressBar->setRange(0,num);
        for(int i=1; i<=num; i++)
        {
            //设置进度条的值
            progressBar->setValue(i);
        }
    }else if(comboBox->currentIndex() == 1)
    {
        //创建一个进度条对话框
        QProgressDialog *progressDlg = new QProgressDialog(this);
        //设置进度对话框出现所需等待的时间
        progressDlg->setMinimumDuration(5);
        progressDlg->setWindowTitle(tr("Please wait"));
        progressDlg->setLabelText(tr("Copy..."));
        progressDlg->setRange(0,num);
        progressDlg->exec();
        for(int i=1; i<=num; i++)
        {
            progressDlg->setValue(i);
        }
    }
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值