Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement Qt Mask layer form

2025-04-09 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 implement the Qt mask layer form". Interested friends may wish to have 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 mask layer form.

I. Preface

In some projects, the original main form needs to be masked behind the pop-up form to highlight the pop-up window, and it suddenly occurred to me that I had written a global screenshot before, which was consistent in principle and used to change it. You just need to introduce a header file and implementation file, and then set the class name of the main form that needs to be masked and the possible pop-up window form in the main form. it's as simple as that. Multiple form lists can be supported. The principle is very simple, first install the event filter, intercept the QEvent::Show event, get the current form, if in the list of forms that need to be masked, then pop up a translucent form with the same size as the pop-up form, and then activate the current pop-up form.

2. Code idea / / usage / / the first step is to set the parent form MaskWidget::Instance ()-> setMainWidget (this) that needs to be masked; / / the second step is to set which pop-up window forms need to be masked QStringList dialogNames;dialogNames dialogNames! = dialogNames) {this- > dialogNames = dialogNames;}} void MaskWidget::setOpacity (double opacity) {this- > setWindowOpacity (opacity);} void MaskWidget::setBgColor (const QColor & bgColor) {QPalette palette = this- > palette () Palette.setBrush (QPalette::Background, bgColor); this- > setPalette (palette);} void MaskWidget::showEvent (QShowEvent *) {if (mainWidget! = 0) {this- > setGeometry (mainWidget- > geometry ());}} bool MaskWidget::eventFilter (QObject * obj, QEvent * event) {if (event- > type () = QEvent::Show) {if (dialogNames.contains (obj- > objectName () {this- > show () This- > activateWindow (); QWidget * w = (QWidget *) obj; w-> activateWindow ();}} else if (event- > type () = = QEvent::Hide) {if (obj- > objectName ()) {this- > hide () }} else if (event- > type () = = QEvent::WindowActivate) {/ / when the main form is activated, activate the mask layer if (mainWidget! = 0) {if (obj- > objectName () = = mainWidget- > objectName ()) {if (this- > isVisible ()) {this- > activateWindow () }} return QObject::eventFilter (obj, event);} 3. Effect diagram

At this point, I believe that everyone on the "Qt mask layer form 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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report