如何使用Qt自定义控件实现圆圈加载进度条

发布时间:2021-09-27 14:25:26 作者:小新
来源:亿速云 阅读:150

这篇文章主要介绍了如何使用Qt自定义控件实现圆圈加载进度条,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

思路:画一个占270度的圆弧,然后定义一个定时器,定时旋转坐标系,实现旋转的效果。圆弧需要使用渐变色,实现颜色越来越浅的效果

关键代码:CMProcessBar1.cpp

CMProcessBar1::CMProcessBar1(QWidget *parent) :  QWidget(parent),  ui(new Ui::CMProcessBar1){  ui->setupUi(this);  QTimer *timer = new QTimer;  connect(timer,QTimer::timeout,this,updaterRotation);// 定时旋转坐标系  timer->start(3);//定时3毫秒}CMProcessBar1::~CMProcessBar1(){  delete ui;}void CMProcessBar1::updaterRotation(){ //循环360度旋转坐标系  rotation++;  if(rotation == 360){    rotation = 0;  }  update();}void CMProcessBar1::paintEvent(QPaintEvent *event){//根据QPaintPath画出渐变色的圆弧  int width = this->width();  int height = this->height();  int side = qMin(width, height);  QPainter painter(this);  painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);  painter.translate(width / 2, height / 2);  painter.scale(side / 200.0, side / 200.0);  QConicalGradient gra(QPoint(0,0),0);  gra.setColorAt(0,QColor("#3BB6FE"));  gra.setColorAt(1,QColor("#FFFFFF"));  QBrush brush(gra);  int radis = 40;  int sider = 5;  QRect rect(-radis,-radis,radis*2,radis*2);  QPainterPath path;  path.arcTo(rect,0, 270);  QPainterPath subPath;  subPath.addEllipse(rect.adjusted(sider, sider, -sider, -sider));  path = path-subPath;  painter.setBrush(brush);//QColor("#66CFFF")  painter.setPen(Qt::NoPen);  painter.rotate(rotation);  painter.drawPath(path);}

感谢你能够认真阅读完这篇文章,希望小编分享的“如何使用Qt自定义控件实现圆圈加载进度条”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!

推荐阅读:
  1. QT自定义控件消息实现
  2. 如何用纯CSS3实现页面圆圈加载效果

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

qt

上一篇:Ubuntu中如何使用Ubuntu拷贝和刻录CD及DVD光盘

下一篇:如何解决CentOS使用MPlayer有图像无声音

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》