打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
[Qt 练习]QProgressBar
userphoto

2015.05.08

关注
转载:http://blog.chinaunix.net/uid-27225886-id-3352398.html
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();
}
运行效果图
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
自定义控件之------QProgressBar的自定义
02、Qt定时器及实现(详解)
Qt之QTimer
【pyqt5学习】
Qt-----进度条QProgressBar
设计Qt风格的C++API | 筒子楼
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服