本文實例為大家分享了Qt實現(xiàn)圓圈加載進度條的具體代碼,供大家參考,具體內(nèi)容如下
先看效果圖:
思路:畫一個占270度的圓弧,然后定義一個定時器,定時旋轉(zhuǎn)坐標系,實現(xiàn)旋轉(zhuǎ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);// 定時旋轉(zhuǎn)坐標系 timer->start(3);//定時3毫秒 } CMProcessBar1::~CMProcessBar1() { delete ui; } void CMProcessBar1::updaterRotation(){ //循環(huán)360度旋轉(zhuǎn)坐標系 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); }
另外有需要云服務器可以了解下創(chuàng)新互聯(lián)建站www.chinadenli.net,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
網(wǎng)頁名稱:Qt自定義控件實現(xiàn)圓圈加載進度條-創(chuàng)新互聯(lián)
文章位置:http://www.chinadenli.net/article12/dsghgc.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、網(wǎng)站營銷、手機網(wǎng)站建設、響應式網(wǎng)站、移動網(wǎng)站建設、定制網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)