QT進度條QProgressBar的練習(定制QProgressBar,單獨成為一個控件)


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();
}
復制代碼

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

http://www.cnblogs.com/luoxiang/p/4159881.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM