Chinaunix首页 | 论坛 | 博客
  • 博客访问: 44978
  • 博文数量: 12
  • 博客积分: 325
  • 博客等级: 一等列兵
  • 技术积分: 170
  • 用 户 组: 普通用户
  • 注册时间: 2012-08-02 12:08
文章分类

全部博文(12)

文章存档

2012年(12)

我的朋友

分类: LINUX

2012-09-19 11:07:14

progressbar.h

点击(此处)折叠或打开

  1. #ifndef PROGRESSBAR_H
  2. #define PROGRESSBAR_H
  3. #include <QProgressBar>
  4. class QString;
  5. class ProgressBar: public QProgressBar
  6. {
  7.     Q_OBJECT
  8. public:
  9.     ProgressBar(QWidget *parent = 0):QProgressBar(parent){}
  10.     QString strText;
  11. public slots:
  12.     void stepOne();

  13. };

  14. #endif // PROGRESSBAR_H

progressbar.cpp

点击(此处)折叠或打开

  1. #include "progressbar.h"
  2. #include <QString>
  3. void ProgressBar::stepOne()
  4. {
  5.     if(this->value()+1 <= this->maximum())
  6.     {
  7.         this->setValue(this->value()+1);

  8.         strText = "QProgressBar Test : "+this->text();
  9.         this->setWindowTitle(strText);
  10.     }
  11.     else
  12.     {
  13.         this->setValue(this->minimum());
  14.     }
  15. }

main.cpp

点击(此处)折叠或打开

  1. #include <QApplication>
  2. #include <QTimer>
  3. #include "progressbar.h"

  4. int main(int argc, char**argv)
  5. {
  6.     QApplication app(argc, argv);

  7.     //progressBar
  8.     ProgressBar *progressBar = new ProgressBar;
  9.     progressBar->setWindowTitle("QProgressBar Test");
  10.     progressBar->resize(400,40);
  11.     progressBar->setMaximum(100);
  12.     progressBar->setMinimum(0);
  13.     progressBar->setValue(0);

  14.     //define a timer
  15.     QTimer *timer = new QTimer;
  16.     timer->start(500);
  17.     QObject::connect(timer, SIGNAL(timeout()), progressBar, SLOT(stepOne()));
  18.     progressBar->show();
  19.     return app.exec();
  20. }

运行效果图

image

阅读(5171) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~