In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-26 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 color picker". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to implement the Qt color picker.
I. Preface
When working on the UI interface of many projects, I believe that the vast majority of people have copied other people's UI interface, especially the color. After all, nine out of ten programmers have no aesthetic, or aesthetic is like a piece of shit. Everyone's main energy and good points are in writing functions to achieve specific functions. How to put this thing? this is indeed the main responsibility of programmers, but in most small companies. UI also needs programmers to deal with themselves, they can not figure out how to do, learn from it, do not know how to do the color value, use the color picker to click. Qt's built-in grabWindow method can specify the handle to get the corresponding color, so if you want to get the color value for the screen, you can pass it to the handle of the entire screen. The handle of the screen is QApplication::desktop ()-> winId () in Qt. How to get it in real time? of course, the easiest way is to start a timer, which keeps calling this method to get the mouse coordinates and color values of the screen.
Second, the code idea void ColorWidget::showColorValue () {if (! pressed) {return;} int x = QCursor::pos (). X (); int y = QCursor::pos (). Y (); txtPoint- > setText (tr ("xpressed% 1ypura% 2") .arg (x) .arg (y)); QString strDecimalValue, strHex, strTextColor; int red, green, blue;#if (QT_VERSION winId (), x, y, 2, 2) # else QScreen * screen = QApplication::primaryScreen (); QPixmap pixmap = screen- > grabWindow (QApplication::desktop ()-> winId (), x, y, 2,2); # endif if (! pixmap.isNull ()) {QImage image = pixmap.toImage (); if (! image.isNull ()) {if (image.valid (0,0)) {QColor color = image.pixel (0,0) Red = color.red (); green = color.green (); blue = color.blue (); QString strRed = tr ("% 1") .Arg (red & 0xFF, 2,16, QChar ('0'); QString strGreen = tr ("% 1") .Arg (green & 0xFF, 2,16, QChar ('0')) QString strBlue = tr ("% 1") .arg (blue & 0xFF, 2,16, QChar ('0'); strDecimalValue = tr ("% 1,% 2,% 3") .arg (red) .arg (green) .arg (blue); strHex = tr ("#% 1% 2% 3") .arg (strRed.toUpper ()) .arg (strGreen.toUpper ()) .arg (strBlue.toUpper ()) } if {strTextColor = "10,10,10";} else {strTextColor = "255,255,255";} QString str = tr ("background-color: rgb (% 1); color: rgb (% 2)") .arg (strDecimalValue) .arg (strTextColor); labColor- > setStyleSheet (str); txtRgb- > setText (strDecimalValue) TxtWeb- > setText (strHex);} III. Effect diagram
At this point, I believe that everyone on the "Qt color picker how to achieve" have a deeper understanding, might as well to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.