Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Qt Custom Control to realize Circle loading Progress Bar

Shulou Source: shulou.com Published: 2022-06-03 09:36:00 09月30日 Update

This article mainly introduces how to use Qt custom control to achieve circle loading progress bar, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

Idea: draw an arc of 270 degrees, and then define a timer to rotate the coordinate system regularly to achieve the effect of rotation. The arc needs to use a gradient to achieve the effect of lighter and lighter color.

Key code: CMProcessBar1.cpp

CMProcessBar1::CMProcessBar1 (QWidget * parent): QWidget (parent), ui (new Ui::CMProcessBar1) {ui- > setupUi (this); QTimer * timer = new QTimer; connect (timer,QTimer::timeout,this,updaterRotation); / / timing rotation coordinate system timer- > start (3); / / timing 3 milliseconds} CMProcessBar1::~CMProcessBar1 () {delete ui;} void CMProcessBar1::updaterRotation () {/ / cycle 360 degree rotation coordinate system rotation++ If (rotation) {rotation = 0;} update ();} void CMProcessBar1::paintEvent (QPaintEvent * event) {/ / draw a gradual arc according to QPaintPath 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) QConicalGradient gra (QPoint (0jue 0), 0); gra.setColorAt (0Magnum QColor ("# 3BB6FE")); gra.setColorAt (1Magical QColor ("# FFFFFF")); QBrush brush (gra); int radis = 40; int sider = 5; QRect rect (- radis,-radis,radis*2,radis*2); QPainterPath path; path.arcTo (rect,0, 270); QPainterPath subPath; subPath.addEllipse (rect.adjusted (sider, sider,-sider,-sider)); path = path-subPath Painter.setBrush (brush); / / QColor ("# 66CFFF") painter.setPen (Qt::NoPen); painter.rotate (rotation); painter.drawPath (path) } Thank you for reading this article carefully. I hope the article "how to use Qt custom controls to achieve circle loading progress bar" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Articles arcs coordinates coordinate systems circles controls progress effects discoloration code value key interest at the same time timers ideas more friends knowledge ribbon Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Information macOS OPPO Reno Microsoft