Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Qt Custom Control to realize Disc Progress Bar

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly describes how to use Qt custom controls to achieve disc progress bar, the text is very detailed, has a certain reference value, interested friends must read!

specific contents are as follows

Custom Controls II: Disc Progress Bar

The main idea: use qpainter to draw circles and arcs according to the graphic requirements, draw pointers (polygons, specify coordinates), rotate the coordinate system according to the specific value value, so that the pointer achieves the rotation effect. The rotation degree is calculated according to the value value, totaling 360 degrees, and the proportion is calculated. You need to draw the text in the middle, and call the update () method every time you update the value to redraw the interface.

Primary Code: 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); //Draw outer circle paintSide (&painter); paintOutE (&painter); paintLine (&painter);//Draw tick marks paintInE (&painter); paintPoint (&painter);//Draw pointer paintTextE (&painter);//Draw the circle where the text is paintText (&painter);//Draw text paintValue (&painter);//Draw the fill angle corresponding to 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;irotate(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()

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report