码迷,mamicode.com
首页 > 其他好文 > 详细

QT进度条QProgressBar的练习

时间:2014-12-12 16:17:29      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   sp   strong   on   

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();
}

bubuko.com,布布扣

转自:http://blog.chinaunix.net/uid-27225886-id-3352398.html

亲测可用。

QT进度条QProgressBar的练习

标签:style   blog   http   io   ar   color   sp   strong   on   

原文地址:http://www.cnblogs.com/luoxiang/p/4159881.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!