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 simple dashboard

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article will explain in detail how to use Qt custom controls to achieve a simple dashboard. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Qt Custom Control 12: simple Dashboard

Idea: draw a 270-degree arc, the arc is divided into two colors according to the proportion, draw a ball on the arc as a sign, and then the scale and the scale value. The scale line is drawn according to the rotation of the coordinate system, and the scale value is calculated according to the angle to construct a rectangle to draw the scale value (do not use the coordinate system to rotate the scale value, so the angle of the scale value will also rotate, and the written word is not positive, the effect is not good). Finally, draw a value in the center.

Key code:

Void CMPassrate5::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); drawE (& painter); drawEPoint (& painter); drawLine (& painter); drawEText (& painter); drawValue (& painter) } void CMPassrate5::drawE (QPainter* painter) {QRect rect (- radius,-radius,2*radius,2*radius); painter- > save (); painter- > setPen (Qt::NoPen); QPainterPath path; QPainterPath subPath; QPainterPath outPath; QPainterPath outPubPath; outPath.arcTo (rect,-45,outRange); outPubPath.addEllipse (rect.adjusted (side,side,-side,-side)); outPath-= outPubPath; color.setAlpha (100); painter- > setBrush (color); painter- > drawPath (outPath); path.arcTo (rect,-45+outRange,range) SubPath.addEllipse (rect.adjusted); path-= subPath; color.setAlpha; painter- > setBrush (color); painter- > drawPath (path); painter- > restore ();} void CMPassrate5::drawEPoint (QPainter* painter) {/ / the ball position is at the end of outRange painter- > save (); color.setAlpha (180); painter- > setPen (Qt::NoPen); painter- > setBrush (color); float x = (radius-side/2) * qCos ((range+135) * 3.14max 180) Float y = (radius-side/2) * qSin ((range+135) * 3.14pyramid 180); qDebug () save (); / / painter- > rotate (135); painter- > setPen (Qt::black); float textRange = 270.0 / (textCount-1); float x Magi y; for (int I = 0ash idrawText (rect,Qt::AlignCenter,QString::number (item10));} else {QRect rect (xMury 20volume 550,1010) Painter- > drawText (rect,Qt::AlignCenter,QString::number (iTunes 10));}} painter- > restore ();} void CMPassrate5::drawValue (QPainter* painter) {painter- > save (); QPen pen = painter- > pen (); pen.setColor (color); pen.setWidth (2); painter- > setPen (pen); QFont font = painter- > font (); font.setPixelSize (45); painter- > setFont (font); QRect rect (- 25 Lay Lay 25th 50th 50th) Painter- > drawText (rect,Qt::AlignCenter,QString::number (value)); painter- > restore ();}

On "how to use Qt custom controls to achieve simple dashboards" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.

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