您的位置:首页 > 编程语言 > Qt开发

QT学习记录-进度条:

2013-01-30 10:11 253 查看
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_OBJECT
public:
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
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: