Qt自定義控件實(shí)現(xiàn)圓圈加載進(jìn)度條
更新時(shí)間:2019年12月19日 17:12:33 作者:parkchorong
這篇文章主要為大家詳細(xì)介紹了Qt自定義控件實(shí)現(xiàn)圓圈加載進(jìn)度條,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(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);
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Matlab利用遺傳算法GA求解非連續(xù)函數(shù)問題詳解
遺傳算法起源于對(duì)生物系統(tǒng)所進(jìn)行的計(jì)算機(jī)模擬研究。其本質(zhì)是一種高效、并行、全局搜索的方法,能在搜索過程中自動(dòng)獲取和積累有關(guān)搜索空間的知識(shí),并自適應(yīng)地控制搜索過程以求得最佳解。本文將利用其求解非連續(xù)函數(shù)問題,需要的可以參考一下2022-09-09
C語言中你容易忽略的知識(shí)點(diǎn)與技巧總結(jié)
這篇文章主要給大家介紹了關(guān)于C語言中你容易忽略的知識(shí)點(diǎn)與技巧,文中通過實(shí)例代碼以及圖文介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2022-03-03

