In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to realize the Qt battery control". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to realize the Qt battery control".
I. Preface
In this day and age, smartphones are not too popular, everywhere, even grandparents will use smartphones, this time the control to write is the smartphone battery control, pure painter drawing, in fact, you can also use mapping, I estimate that most mobile phones are in the form of stickers, the advantage of mapping is that programmers do not have to worry about drawimage, the speed is very fast. As for this control, there is no technical difficulty, that is, it automatically calculates the amount of electricity currently set, divides 100 equal parts according to the proportion of width, how many pixels each divided, and then the amount of electricity * this ratio is the area of the amount of electricity to be drawn. You can set the alarm power, which is lower than the variable and the whole battery area is shown in red.
Main functions:
You can set the style of the switch button, rounded rectangle / inner circle / outer circle
You can set the background color when selected and unselected
You can set the slider color when selected and unselected
Text that can be set to be displayed
You can set the distance between the slider and the background
Fillet angle can be set
You can set whether the animated transition effect is displayed.
2. Code ideas void Battery::paintEvent (QPaintEvent *) {/ / preparation for drawing, enable anti-aliasing QPainter painter (this); painter.setRenderHints (QPainter::Antialiasing | QPainter::TextAntialiasing); / / draw frame drawBorder (& painter); / / draw background drawBg (& painter); / / draw head drawHead (& painter);} void Battery::drawBorder (QPainter * painter) {painter- > save () Double headWidth = width () / 10; double batteryWidth = width ()-headWidth; / / draw battery frame QPointF topLeft (5,5); QPointF bottomRight (batteryWidth, height ()-5); batteryRect = QRectF (topLeft, bottomRight); painter- > setPen (QPen (borderColorStart, 5)); painter- > setBrush (Qt::NoBrush); painter- > drawRoundedRect (batteryRect, borderRadius, borderRadius); painter- > restore () } void Battery::drawBg (QPainter * painter) {painter- > save (); QLinearGradient batteryGradient (QPointF (0,0), QPointF (0, height ()); if (currentValue setPen (Qt::NoPen); painter- > setBrush (batteryGradient); painter- > drawRoundedRect (rect, bgRadius, bgRadius); painter- > restore ();} void Battery::drawHead (QPainter * painter) {painter- > save (); QPointF headRectTopLeft (batteryRect.topRight () .x (), height () / 3) QPointF headRectBottomRight (width (), height ()-height () / 3); QRectF headRect (headRectTopLeft, headRectBottomRight); QLinearGradient headRectGradient (headRect.topLeft (), headRect.bottomLeft ()); headRectGradient.setColorAt (0.0, borderColorStart); headRectGradient.setColorAt (1.0, borderColorEnd); painter- > setPen (Qt::NoPen); painter- > setBrush (headRectGradient); painter- > drawRoundedRect (headRect, headRadius, headRadius); painter- > restore ();} III.
Thank you for your reading, the above is the content of "how to achieve Qt battery control". After the study of this article, I believe you have a deeper understanding of how to achieve Qt battery control, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
Parameterization 1: be careful: leave a blank line
© 2024 shulou.com SLNews company. All rights reserved.