分享

[Qt 练习]QProgressBar

 tianht 2015-05-08

转载:http://blog./uid-27225886-id-3352398.html

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()+<= 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

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多