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 implement Progress Dashboard

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

Share

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

This article mainly shows you "how to use Qt custom controls to achieve progress dashboard", the content is easy to understand, well-organized, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "how to use Qt custom controls to achieve progress dashboard" this article.

The details are as follows

Idea: a total of 100 peripheral lines (custom, changeable), accounting for a total of 270 degrees, and then draw a complete line according to the idea of first drawing a line and then rotating the coordinate system. Inside is a gray background circle, an arc and the text corresponding to the middle value.

Key code: CMPassrate2.cpp

Void CMPassrate2::paintEvent (QPaintEvent * event) {/ / Interface drawing 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); drawBGE (& painter); / / draw background circle drawTextE (& painter); / / Arc drawText (& painter) where the drawing text is located / / draw the word drawLines (& painter); / / draw the outermost line} void CMPassrate2::updateValue (float value) {/ / provide an external method to update value this- > value = value; update (); / / redraw the interface} void CMPassrate2::drawLines (QPainter* painter) {painter- > save (); QPen pen; pen.setColor (QColor ("# A7DD42")); pen.setWidth (2); painter- > setPen (pen); float range = 270.0/lineCount after each update of value / / customize all the lines to add up to 270degrees, 100lines painter- > rotate (135degrees); / / rotate 135degrees to start drawing lines, a total of 270degrees. QLine line (QPoint (outLineRadius,0), QPoint (innLineRadius,0)); for (int I = 1 political ivalue) {QPen pen; pen.setColor (QColor ("# D7D7D7")); pen.setWidth (2); painter- > setPen (pen);} painter- > drawLine (line); painter- > rotate (range);} painter- > restore ();} void CMPassrate2::drawBGE (QPainter* painter) {painter- > save (); painter- > setPen (Qt::NoPen); painter- > setBrush (QColor (# EAEAEA)) QRect rect (- bgERadius,-bgERadius,bgERadius*2,bgERadius*2); painter- > drawEllipse (rect); painter- > restore ();} void CMPassrate2::drawTextE (QPainter* painter) {painter- > save (); painter- > setPen (Qt::NoPen); painter- > setBrush (QColor ("# 2DC877")); QPainterPath path; QRect rectOut (- textOutRadius,-textOutRadius,textOutRadius*2,textOutRadius*2); path.arcTo (rectOut,0360); QPainterPath subPath; QRect rectInn (- textInnRadius,-textInnRadius,textInnRadius*2,textInnRadius*2); subPath.addEllipse (rectInn) Path-= subPath; painter- > drawPath (path); painter- > restore ();} void CMPassrate2::drawText (QPainter* painter) {painter- > save (); painter- > setPen (QColor ("# 62A0DB")); QRect rectInn (- textInnRadius,-textInnRadius,textInnRadius*2,textInnRadius*2); QFont font = painter- > font (); font.setPixelSize (textSize); painter- > setFont (font); painter- > drawText (rectInn,Qt::AlignCenter,QString::number (value)); painter- > restore () } these are all the contents of the article "how to use Qt custom controls to implement a progress dashboard". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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