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

溫馨提示×

溫馨提示×

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

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

如何使用Qt自定義控件實現圓盤進度條

發布時間:2021-09-27 14:19:31 來源:億速云 閱讀:127 作者:小新 欄目:編程語言

這篇文章主要介紹如何使用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();}

以上是“如何使用Qt自定義控件實現圓盤進度條”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!

向AI問一下細節

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

qt
AI

吴桥县| 五华县| 且末县| 平邑县| 平顺县| 吉林省| 中卫市| 菏泽市| 资兴市| 德清县| 昌图县| 乡宁县| 昌江| 永善县| 武胜县| 寿宁县| 柏乡县| 伊吾县| 无锡市| 略阳县| 漯河市| 轮台县| 安化县| 华坪县| 漾濞| 罗城| 武邑县| 大安市| 上思县| 鄂温| 克拉玛依市| 扬州市| 高青县| 城固县| 梓潼县| 遂溪县| 招远市| 桐城市| 海城市| 南和县| 宜兰市|