首页 > 代码库 > QT进度条QProgressBar的练习
QT进度条QProgressBar的练习
progressbar.h
#ifndef PROGRESSBAR_H#define PROGRESSBAR_H#include <QProgressBar>class QString;class ProgressBar: public QProgressBar{ Q_OBJECTpublic: 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
亲测可用。
QT进度条QProgressBar的练习
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。