Qt自定義控件實(shí)現(xiàn)圓圈加載進(jìn)度條
本文實(shí)例為大家分享了Qt實(shí)現(xiàn)圓圈加載進(jìn)度條的具體代碼,供大家參考,具體內(nèi)容如下
先看效果圖:
思路:畫一個(gè)占270度的圓弧,然后定義一個(gè)定時(shí)器,定時(shí)旋轉(zhuǎn)坐標(biāo)系,實(shí)現(xiàn)旋轉(zhuǎn)的效果。圓弧需要使用漸變色,實(shí)現(xiàn)顏色越來越淺的效果
關(guā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);// 定時(shí)旋轉(zhuǎn)坐標(biāo)系 timer->start(3);//定時(shí)3毫秒 } CMProcessBar1::~CMProcessBar1() { delete ui; } void CMProcessBar1::updaterRotation(){ //循環(huán)360度旋轉(zhuǎn)坐標(biāo)系 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); }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。
您可能感興趣的文章
- 01-10數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)-用棧實(shí)現(xiàn)表達(dá)式求值的方法詳解
- 01-10使用OpenGL實(shí)現(xiàn)3D立體顯示的程序代碼
- 01-10求斐波那契(Fibonacci)數(shù)列通項(xiàng)的七種實(shí)現(xiàn)方法
- 01-10C語言 解決不用+、-、×、÷數(shù)字運(yùn)算符做加法
- 01-10使用C++實(shí)現(xiàn)全排列算法的方法詳解
- 01-10用C++實(shí)現(xiàn)DBSCAN聚類算法
- 01-10深入全排列算法及其實(shí)現(xiàn)方法
- 01-10全排列算法的非遞歸實(shí)現(xiàn)與遞歸實(shí)現(xiàn)的方法(C++)
- 01-10用C語言實(shí)現(xiàn)單鏈表的各種操作(一)
- 01-10用C語言實(shí)現(xiàn)單鏈表的各種操作(二)


閱讀排行
本欄相關(guān)
- 04-02c語言函數(shù)調(diào)用后清空內(nèi)存 c語言調(diào)用
- 04-02func函數(shù)+在C語言 func函數(shù)在c語言中
- 04-02c語言的正則匹配函數(shù) c語言正則表達(dá)
- 04-02c語言用函數(shù)寫分段 用c語言表示分段
- 04-02c語言中對數(shù)函數(shù)的表達(dá)式 c語言中對
- 04-02c語言編寫函數(shù)冒泡排序 c語言冒泡排
- 04-02c語言沒有round函數(shù) round c語言
- 04-02c語言分段函數(shù)怎么求 用c語言求分段
- 04-02C語言中怎么打出三角函數(shù) c語言中怎
- 04-02c語言調(diào)用函數(shù)求fibo C語言調(diào)用函數(shù)求
隨機(jī)閱讀
- 04-02jquery與jsp,用jquery
- 01-10使用C語言求解撲克牌的順子及n個(gè)骰子
- 01-10C#中split用法實(shí)例總結(jié)
- 08-05織夢dedecms什么時(shí)候用欄目交叉功能?
- 01-11ajax實(shí)現(xiàn)頁面的局部加載
- 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 08-05DEDE織夢data目錄下的sessions文件夾有什
- 01-10delphi制作wav文件的方法