QT学习记录-进度条:

来源:互联网 发布:win7网络图标不见 编辑:程序博客网 时间:2024/05/29 02:11

QT学习记录-进度条:

在QT中可以用QProgressBar或着QProgressDialog来实现进度条。

 

QProgressDialog:

QProgressBar:

 

// progress.h#ifndefPROGRESS_H#definePROGRESS_H#include<QtGui/QMainWindow>#include<QPushButton>#include<QProgressBar>#include<QProgressDialog>#include<QVBoxLayout>classprogress:publicQMainWindow{    Q_OBJECTpublic:    progress(QWidget*parent=0);publicslots:    voidbarstart(void);private:    QPushButton*startbutton;    QProgressBar*bar;    QProgressDialog*process;};#endif//PROGRESS_H // progress.cpp#include"progress.h"#include<windows.h>progress::progress(QWidget*parent)    :QMainWindow(parent){    resize(500,150);    startbutton=newQPushButton("clickme!",this);    bar=newQProgressBar(this);    startbutton->setGeometry(30,20,100,30);    bar->setGeometry(30,100,300,20);    connect(startbutton,SIGNAL(clicked()),this,SLOT(barstart()));}voidprogress::barstart(void){#if1   //QProgressBar       unsignedinti,j;       bar->setRange(0,5000-1);       for(i=0;i<5000;i++)       {           //for(j=0;j<5000;j++);           //Sleep(10);           bar->setValue(i);       }#else   //QProgressDialog对话框的形式        QProgressDialogprocess(this);        process.setLabelText(tr("processing..."));        process.setRange(0,5000-1);        process.setModal(true);        process.setCancelButtonText(tr("cancel"));        for(inti=0;i<5000;i++)        {            for(intj=0;j<20000;j++);            process.setValue(i);            if(process.wasCanceled())                break;        }#endif} 


原创粉丝点击