91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Qt自定義控件實現圓盤進度條

發布時間:2020-10-07 06:52:26 來源:腳本之家 閱讀:155 作者:parkchorong 欄目:編程語言

本文實例為大家分享了Qt圓盤進度條的具體代碼,供大家參考,具體內容如下

自定義控件二:圓盤進度條

上效果圖:

Qt自定義控件實現圓盤進度條

主要思路:使用qpainter根據圖形需求 畫圓和圓弧,畫指針(多邊形,指定坐標即可),根據具體的value值旋轉坐標系,使指針達到旋轉效果,旋轉度數是根據value值,總共360度,占比求得。最中間需要畫文字上去,每次更新value時調用update()方法,重繪界面。

主要代碼:CMPassrate1.cpp

void CMPassrate1::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);

  //繪制外圓
  paintSide(&painter);
  paintOutE(&painter);
  
  paintLine(&painter);//繪制刻度線
  paintInE(&painter);
  paintPoint(&painter);//繪制指針
  paintTextE(&painter);//繪制文字所在的圓
  paintText(&painter);//繪制文字
  paintValue(&painter);//繪制value對應的填充角度
}

void CMPassrate1::paintSide(QPainter *painter){
  int radis = outRadis;
  QRect rect(-radis,-radis,radis*2,radis*2);
  painter->save();
  painter->setBrush(QBrush(QColor("#505050")));
  painter->setPen(Qt::NoPen);
  painter->drawEllipse(rect);
  painter->restore();
}

void CMPassrate1::paintOutE(QPainter *painter){
  int radis = outRadis-side;
  QRect rect(-radis,-radis,radis*2,radis*2);
  painter->save();
  painter->setBrush(QBrush(QColor("#868686")));
  painter->setPen(Qt::NoPen);
  painter->drawEllipse(rect);
  painter->restore();
}

void CMPassrate1::paintLine(QPainter *painter){
  int lineStart = outRadis-3;
  painter->save();
  painter->setPen(QColor("#868686"));
  int range = 360/12;
  for(int i = 0;i<12;i++){
    painter->rotate(range);
    painter->drawLine(QPoint(lineStart,0),QPoint(outRadis,0));
  }
  painter->restore();
}

void CMPassrate1::paintInE(QPainter *painter){
  int radis = inRadis;
  QRect rect(-radis,-radis,radis*2,radis*2);
  painter->save();
  painter->setBrush(QBrush(QColor("#646464")));
  painter->setPen(Qt::NoPen);
  painter->drawEllipse(rect);
  painter->restore();
}

void CMPassrate1::paintTextE(QPainter *painter){
  int radis = 23;
  QRect rect(-radis,-radis,radis*2,radis*2);
  painter->save();
  painter->setBrush(QBrush(QColor("#FFFFFF")));
  painter->setPen(Qt::NoPen);
  painter->drawEllipse(rect);
  painter->restore();
}

void CMPassrate1::paintPoint(QPainter *painter){
   painter->save();
   const QPoint points[3] = {
       QPoint(10,0),
       QPoint(-10,0),
       QPoint(0,inRadis-5)
     };
   int range = ((double)value/100)*360;
   painter->rotate(range);
   painter->setPen(Qt::NoPen);
   painter->setBrush(QBrush(QColor("#66CFFF")));
   painter->drawConvexPolygon(points,3);


   painter->restore();
}

void CMPassrate1::paintText(QPainter *painter){
  int radis = 23;
  QRect rect(-radis,-radis,radis*2,radis*2);
  painter->save();
  painter->setBrush(QBrush(QColor("#000000")));
  painter->setPen(QPen(QColor("#000000")));
  QFont font = painter->font();
  font.setPixelSize(20);
  painter->setFont(font);
  painter->drawText(rect,Qt::AlignCenter,QString("%1%").arg(QString::number(value)));
  painter->restore();
}

void CMPassrate1::paintValue(QPainter *painter){
  int oRandis = outRadis-side;
  qDebug()<<"value::"<<value;
  int rangle = ((double)value/100)*360;
  QRectF rect(-oRandis, -oRandis, oRandis << 1, oRandis << 1);
  QPainterPath path;
  qDebug()<<"rangle:"<<rangle<<" start:"<<270-rangle;
  path.arcTo(rect, 270-rangle, rangle);

  // QRectF(-120, -120, 240, 240)
  QPainterPath subPath;
  subPath.addEllipse(rect.adjusted((oRandis-inRadis),(oRandis-inRadis),-(oRandis-inRadis),-(oRandis-inRadis)));

  // path為扇形 subPath為橢圓
  path -= subPath;
  painter->save();
  painter->setBrush(valueColor);
  painter->setPen(Qt::NoPen);
  painter->drawPath(path);
  painter->restore();
}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

维西| 古蔺县| 金川县| 宣威市| 沧源| 蓬莱市| 永定县| 三河市| 澎湖县| 文昌市| 郓城县| 东乌珠穆沁旗| 广昌县| 龙江县| 合山市| 汽车| 泗阳县| 仪陇县| 平泉县| 宁国市| 资源县| 平乐县| 临桂县| 南部县| 上林县| 武鸣县| 龙口市| 喀喇沁旗| 额尔古纳市| 凤台县| 拜城县| 新乡市| 慈溪市| 玛曲县| 兴业县| 介休市| 盐边县| 高安市| 望谟县| 邹平县| 绵竹市|