真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

如何使用Qt自定義控件實(shí)現(xiàn)多彩色儀表盤-創(chuàng)新互聯(lián)

小編給大家分享一下如何使用Qt自定義控件實(shí)現(xiàn)多彩色儀表盤,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

為墾利等地區(qū)用戶提供了全套網(wǎng)頁(yè)設(shè)計(jì)制作服務(wù),及墾利網(wǎng)站建設(shè)行業(yè)解決方案。主營(yíng)業(yè)務(wù)為成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、墾利網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠(chéng)的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!

具體內(nèi)容如下

Qt自定義控件4:多彩色儀表盤

思路:外圍三色的圓弧 紅:藍(lán):綠 = 1:2:1,總共占270度??潭染€是根據(jù)所在圓弧的顏色而畫,刻度線的角度也是根據(jù)坐標(biāo)系的旋轉(zhuǎn)而畫??潭戎凳歉鶕?jù)刻度線的角度得到所要畫的刻度的左上角的坐標(biāo),然后構(gòu)成一個(gè)矩形,根據(jù)矩形畫出刻度值。指針是根據(jù)四個(gè)點(diǎn)的坐標(biāo)直接畫的四邊形,再旋轉(zhuǎn)坐標(biāo)系實(shí)現(xiàn)指針旋轉(zhuǎn)的效果。下方的文字直接得到坐標(biāo)橫縱坐標(biāo)位置得到矩形畫出value的值

關(guān)鍵代碼:CMPassrate3.cpp

void CMPassrate3::paintEvent(QPaintEvent *event){  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);  drawBG(&painter);  drawE(&painter);  drawLine(&painter);  drawText(&painter);  drawBootomText(&painter);  drawPoint(&painter);}void CMPassrate3::drawE(QPainter* painter){  painter->setPen(Qt::NoPen);  QRect rectOut(-outRadius,-outRadius,2*outRadius,2*outRadius);  QRect rectInn(-innRadius,-innRadius,2*innRadius,2*innRadius);  painter->save();  painter->setBrush(QColor("#04EEB2"));  QPainterPath path;  path.arcTo(rectOut,-45,270.0/4);  QPainterPath subPath;  subPath.addEllipse(rectInn);  path -= subPath;  painter->drawPath(path);  painter->restore();  painter->save();  QPainterPath bluePath;  QPainterPath blueSubPath;  painter->setBrush(QColor("#2DC5F6"));  bluePath.arcTo(rectOut,-45+(270.0/4),270.0/2);  blueSubPath.addEllipse(rectInn);  bluePath -= blueSubPath;  painter->drawPath(bluePath);  painter->restore();  painter->save();  QPainterPath redPath;  QPainterPath redSubPath;  painter->setBrush(QColor("#FA468C"));  redPath.arcTo(rectOut,-45+270.0*3/4,270.0/4);  redSubPath.addEllipse(rectInn);  redPath -= redSubPath;  painter->drawPath(redPath);  painter->restore();}void CMPassrate3::drawLine(QPainter* painter){  painter->save();  painter->rotate(135);  //270/8度一格  for(int i = 0;i<9;i++){    if(i<3){      painter->setPen(QColor("#FA468C"));    }else if(i<6){      painter->setPen(QColor("#2DC5F6"));    }else{      painter->setPen(QColor("#04EEB2"));    }    QLine line(QPoint(lineStart,0),QPoint(innRadius,0));    painter->drawLine(line);    painter->rotate(270.0/8);  }  painter->restore();}void CMPassrate3::drawPoint(QPainter* painter){  const QPoint point[4]{    QPoint(0,0),QPoint(0,6),QPoint((lineStart-3)*qCos(135*3.14/180),(lineStart-3)*qSin(135*3.14/180)),QPoint(-6,0)  };  float range = 270.0/100*value;  painter->save();  painter->setBrush(QColor("#C2E481"));  painter->rotate(range);  painter->drawConvexPolygon(point,4);  painter->restore();}void CMPassrate3::drawBG(QPainter* painter){//可以自行添加背景圖片實(shí)現(xiàn)更加精美的效果//  painter->save();//  QImage image(":/image/images/bg1.jpg");//  QRect rect(-this->width(),-this->height(),this->width()*2,this->height()*2);//  painter->drawImage(rect,image);//  painter->restore();}void CMPassrate3::drawText(QPainter *painter){  painter->save();  //初始為  painter->setPen(Qt::black);  QFont font = painter->font();  font.setPixelSize(8);  painter->setFont(font);  float x,y;  for(float i =0;i<=100;i+=12.5){    x = lineStart*qCos((135+(270.0/8)*((i+1)/12.5))*3.14/180);    y = lineStart*qSin((135+(270.0/8)*((i+1)/12.5))*3.14/180);    QRect rect;    if(i<50){      rect.setX(x);      rect.setY(y);    }else if(i>50){      rect.setX(x-17);      rect.setY(y-7);    }else{      rect.setX(x);      rect.setY(y);    }    rect.setWidth(17);    rect.setHeight(10);    painter->drawText(rect,Qt::AlignCenter,QString::number(i));  }  painter->restore();}void CMPassrate3::drawBootomText(QPainter *painter){  painter->save();  painter->setPen(Qt::black);  QFont font = painter->font();  font.setPixelSize(25);  painter->setFont(font);  painter->translate(0,outRadius-12);  int length = 20;  QRect rect(-length,-length,length*2,length*2);  painter->drawText(rect,Qt::AlignCenter,QString::number(value));  painter->restore();}

以上是“如何使用Qt自定義控件實(shí)現(xiàn)多彩色儀表盤”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!


分享標(biāo)題:如何使用Qt自定義控件實(shí)現(xiàn)多彩色儀表盤-創(chuàng)新互聯(lián)
URL標(biāo)題:http://weahome.cn/article/cojsgi.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部