In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
            
                    
                
2025-11-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to achieve Qt highlight button control, the text is very detailed, has a certain reference value, interested friends must read!
I. Foreword
This highlight button control is not my original work, is a reference to the Qt world of a master figure Gongsun Ergou's work, you are interested can go to search to see, in the original author's code, I just changed to their own control frame structure, and then improve some details, such as adding a variety of color settings, provide direct switching color simulation traffic lights and so on.
In fact, the whole programming learning process is a process of continuous learning and reference, constantly referring to other people's code, referring to the code with demo, referring to help documents, search-oriented programming, etc., constantly trying to solve problems first, and thinking about how to better ways, it is suggested that in the process of learning programming, it is very important to read more help documents, basically covering the description of all functions, at least the basic description is there, and then referring to the demo with itself, so that after several years, The level of assurance is rising.
Highlight button control function:
Text can be set, centered
Text color can be set
You can set the gradient color of the outer border
You can set the border gradient color
Background color can be set
Can directly call the built-in settings Green/Red/Yellow/Black/Blue and other public slot functions
Can be set whether it can be moved in the container and used as an object
Set whether to display rectangles
Alarm color + non-alarm color can be set
Can control start alarm and stop alarm, alarm flashing
Second, code ideas//draw the outer border void LightButton::drawBorderOut(QPainter *painter){ int radius = 99; painter->save(); painter->setPen(Qt::NoPen); QLinearGradient borderGradient(0, -radius, 0, radius); borderGradient.setColorAt(0, borderOutColorStart); borderGradient.setColorAt(1, borderOutColorEnd); painter->setBrush(borderGradient); painter->drawEllipse(-radius, -radius, radius * 2, radius * 2); painter->restore();}//Draw inner border void LightButton::drawBorderIn(QPainter *painter){ int radius = 90; painter->save(); painter->setPen(Qt::NoPen); QLinearGradient borderGradient(0, -radius, 0, radius); borderGradient.setColorAt(0, borderInColorStart); borderGradient.setColorAt(1, borderInColorEnd); painter->setBrush(borderGradient); painter->drawEllipse(-radius, -radius, radius * 2, radius * 2); painter->restore();}//Draw main background void LightButton::drawBg(QPainter *painter){ int radius = 80; painter->save(); painter->setPen(Qt::NoPen); painter->setBrush(bgColor); painter->drawEllipse(-radius, -radius, radius * 2, radius * 2); painter->restore();}//Draw text void LightButton::drawText(QPainter *painter){ if (text.isEmpty()) { return; } int radius = 100; painter->save(); QFont font; font.setPixelSize(85); painter->setFont(font); painter->setPen(textColor); QRect rect(-radius, -radius, radius * 2, radius * 2); painter->drawText(rect, Qt::AlignCenter, text); painter->restore();}//Draw mask layer void LightButton::drawOverlay(QPainter *painter){ if (! showOverlay) { return; } int radius = 80; painter->save(); painter->setPen(Qt::NoPen); QPainterPath smallCircle; QPainterPath bigCircle; radius -= 1; smallCircle.addEllipse(-radius, -radius, radius * 2, radius * 2); radius *= 2; bigCircle.addEllipse(-radius, -radius + 140, radius * 2, radius * 2); //The highlight is shaped as a small circle minus the part of the big circle QPainterPath highlight = smallCircle - bigCircle; QLinearGradient linearGradient(0, -radius / 2, 0, 0); overlayColor.setAlpha(100); linearGradient.setColorAt(0.0, overlayColor); overlayColor.setAlpha(30); linearGradient.setColorAt(1.0, overlayColor); painter->setBrush(linearGradient); painter->rotate(-20); painter->drawPath(highlight); Painter->restore();} III. Effect drawing
The above is "Qt how to achieve highlight button control" all the content of this article, thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to 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.

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.