zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    9.17考试
    Something
    tesuto-Mobius
    7.22考试
    填坑...P1546 最短网络 Agri-Net
    P1125 笨小猴
    P2822 组合数问题
    致我们曾经刷过的水题
    Luogu P1186 玛丽卡
    Luogu P1726 上白泽慧音
  • 原文地址:https://www.cnblogs.com/findumars/p/5994561.html
Copyright © 2011-2022 走看看