In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.