转载:http://blog.chinaunix.net/uid-27225886-id-3352398.html
progressbar.h
点击(此处)折叠或打开
#ifndef PROGRESSBAR_H
#define PROGRESSBAR_H
#include <QProgressBar>
class QString;
class ProgressBar: public QProgressBar
{
Q_OBJECT
public:
ProgressBar(QWidget *parent = 0):QProgressBar(parent){}
QString strText;
public slots:
void stepOne();
};
#endif // PROGRESSBAR_H
progressbar.cpp
点击(此处)折叠或打开
#include "progressbar.h"
#include <QString>
void ProgressBar::stepOne()
{
if(this->value()+1 <= this->maximum())
{
this->setValue(this->value()+1);
strText = "QProgressBar Test : "+this->text();
this->setWindowTitle(strText);
}
else
{
this->setValue(this->minimum());
}
}
main.cpp
点击(此处)折叠或打开
#include <QApplication>
#include <QTimer>
#include "progressbar.h"
int main(int argc, char**argv)
{
QApplication app(argc, argv);
//progressBar
ProgressBar *progressBar = new ProgressBar;
progressBar->setWindowTitle("QProgressBar Test");
progressBar->resize(400,40);
progressBar->setMaximum(100);
progressBar->setMinimum(0);
progressBar->setValue(0);
//define a timer
QTimer *timer = new QTimer;
timer->start(500);
QObject::connect(timer, SIGNAL(timeout()), progressBar, SLOT(stepOne()));
progressBar->show();
return app.exec();
}
运行效果图
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。