In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 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 realize the Qt picture switch control". In the daily operation, I believe many people have doubts about how to realize the Qt picture switch control. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to realize the Qt picture switch control". Next, please follow the editor to study!
I. Preface
Since entering the era of smart phones, all kinds of APP are very popular. There are many popular elements in the APP on the phone. I like the switch button very much. There are many switches to control some operations. In the WINFORM project, if CheckBox is also changed into a switch button, it will also add a lot of freshness to the project. Following the previous practice, I still like to directly PS the picture and use the drawimage method to draw the picture to the user control, enabling double buffering and background transparency. Some people say that PS a beautiful picture is not very easy, need to be professional, here is a good way, so you can also get these pictures, in fact, most of the APP can be opened with decompression software, the extension name can be changed to .zip Decompressed generally contains the vast majority of images, found that the vast majority of APP like to use pictures as the background to show some effects, rather than using the original code to draw. Tencent is Tencent, a big company! The pictures designed by other people's artist MM are really needless to say, absolutely first-rate. Every time Mobile QQ upgrades a version, he will come down and extract the beautiful picture icons and so on, so that the project can use it. This will not be regarded as piracy.
2. ImageSwitch::ImageSwitch (QWidget * parent): QWidget (parent) {isChecked = false; buttonStyle = ButtonStyle_2; imgOffFile = ": / image/btncheckoff2.png"; imgOnFile = ": / image/btncheckon2.png"; imgFile = imgOffFile;} void ImageSwitch::mousePressEvent (QMouseEvent *) {imgFile = isChecked? ImgOffFile: imgOnFile; isChecked =! isChecked; this- > update ();} void ImageSwitch::paintEvent (QPaintEvent *) {QPainter painter (this); painter.setRenderHints (QPainter::SmoothPixmapTransform); QImage img (imgFile); img = img.scaled (this- > size (), Qt::KeepAspectRatio, Qt::SmoothTransformation); / / automatically center int pixX = rect (). Center (). X ()-img.width () / 2 Int pixY = rect (). Center (). Y ()-img.height () / 2; QPoint point (pixX, pixY); painter.drawImage (point, img);} bool ImageSwitch::getChecked () const {return isChecked;} ImageSwitch::ButtonStyle ImageSwitch::getButtonStyle () const {return this- > buttonStyle;} QSize ImageSwitch::sizeHint () const {return QSize (87,28);} QSize ImageSwitch::minimumSizeHint () const {return QSize (87,28) } void ImageSwitch::setChecked (bool isChecked) {if (this- > isChecked! = isChecked) {this- > isChecked = isChecked; imgFile = isChecked? ImgOnFile: imgOffFile; this- > update ();}} void ImageSwitch::setButtonStyle (const ImageSwitch::ButtonStyle & buttonStyle) {if (this- > buttonStyle! = buttonStyle) {this- > buttonStyle = buttonStyle; if (buttonStyle = = ButtonStyle_1) {imgOffFile = ": / image/btncheckoff1.png"; imgOnFile = ": / image/btncheckon1.png"; this- > resize (87,28) } else if (buttonStyle = = ButtonStyle_2) {imgOffFile = ": / image/btncheckoff2.png"; imgOnFile = ": / image/btncheckon2.png"; this- > resize (87,28);} else if (buttonStyle = = ButtonStyle_3) {imgOffFile = ": / image/btncheckoff3.png"; imgOnFile = ": / image/btncheckon3.png" This- > resize (96,38);} imgFile = isChecked? ImgOnFile: imgOffFile; setChecked (isChecked); this- > update (); updateGeometry ();}} III.
At this point, the study of "how to implement the Qt picture switch control" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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
© 2024 shulou.com SLNews company. All rights reserved.