Qt自定義控件實現(xiàn)圓圈加載進度條
更新時間:2019年12月19日 17:12:33 作者:parkchorong
這篇文章主要為大家詳細介紹了Qt自定義控件實現(xiàn)圓圈加載進度條,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了Qt實現(xiàn)圓圈加載進度條的具體代碼,供大家參考,具體內容如下
先看效果圖:
思路:畫一個占270度的圓弧,然后定義一個定時器,定時旋轉坐標系,實現(xiàn)旋轉的效果。圓弧需要使用漸變色,實現(xiàn)顏色越來越淺的效果
關鍵代碼: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(){ //循環(huán)360度旋轉坐標系 rotation++; if(rotation == 360){ rotation = 0; } update(); } void CMProcessBar1::paintEvent(QPaintEvent *event){//根據(jù)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); }
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
C語言標準庫<math.h>和<setjmp.h>的實現(xiàn)
本文主要介紹了C語言標準庫<math.h>和<setjmp.h>的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-11-11C語言中關于庫函數(shù) qsort 的模擬實現(xiàn)過程
庫函數(shù)的模擬實現(xiàn)有利于我們去深入了解這個函數(shù)內部是怎樣實現(xiàn)的,以及學習它的算法,使我們更加了解這個函數(shù)該怎樣去使用,接下來我將詳細的介紹qsort的應用及用法,并且用代碼模擬實現(xiàn)它們的功能2021-09-09C++中用substr()函數(shù)消除前后空格的解決方法詳解
本篇文章是對C++中用substr()函數(shù)消除前后空格的方法進行了詳細的分析介紹,需要的朋友參考下2013-05-05OpenCV+Qt實現(xiàn)圖像處理操作工具的示例代碼
這篇文章主要介紹了利用OpenCV+Qt實現(xiàn)圖像處理操作工具,可以實現(xiàn)雪花屏、高斯模糊、中值濾波、毛玻璃等操作,感興趣的可以了解一下2022-08-08