In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how Qt borderless form to achieve the simulation of modal form jitter effect, I hope you will learn something after reading this article, let's discuss it together!
Qt borderless form-simulated modal form jitter effect I. Overview
Using Qt to develop windows client interface is really a sharp tool, taking into account the performance at the same time, the speed is also relatively good. With the help of qss, a beautiful interface is fine.
To make a beautiful interface, it is necessary to rewrite a title bar, then we certainly need to use a borderless Qt::FramelessWindowHint form property provided to us by Qt. However, after setting this property, there are a series of problems, such as dragging and dropping the title bar, zooming in and out of the window, and most importantly, the native dithering effect of some modal forms is gone.
Now that there is a problem, we have to find a way to solve it.
Window zooming in and out and dragging and dropping provided a class file support in earlier versions of Qt, and the author also carried out secondary development of this file, which can provide more rich functions. Since dragging and zooming have little to do with this article, there is no explanation here. Students who are interested can go to the Qt borderless form-when maximizing, support drag and restore to view here.
In this article, we will talk about how to achieve a flashing effect if you click on an application interface other than the modeless form when the modal form pops up.
Flicker is just an external information exchange, if you want some other interactive effects, you can achieve it yourself.
Second, effect display
As shown in the effect picture, a simple effect is made.
When you click on the main application, the color of the pop-up modal form border changes, achieving a jitter effect.
When you click on the desktop, the modal form also has a state change when it loses focus.
Third, function realization
To achieve the window jitter effect, we first need to understand the windows message ID, know which windows message we want to accept to complete the flicker effect, and the second is how Qt receives such native windows messages.
Windowws message
Learn about windows message ID, open a search engine casually, enter the keyword Windows message ID, and then you can find a large number of articles specifically about windwos messages. Here the blogger found an article on the list of windows messages, Windows messages ID description, basically all of the messages in the article are annotated in Chinese, so it is easier to read.
Then we will find that there is a message that may be what we need, as shown in the following figure.
Article 130 content, ID is 86 WM_NCACTIVATE message. The message is actually triggered when the non-client area of a window needs to be changed to show whether it is active or inactive. It sounds interesting, like it's what we need, and then we'll try.
Qt receives native messages
Now that the message ID is locked, the next step is to receive the message and then implement the UI interaction of the response.
So the question is, how does the Qt window receive windows native messages?
Of course, this question does not confuse us. Why Qt is so popular is not just because the library is encapsulated well, but because it helps to document more fully. Next step you should know what to do, open the help document, and then search the keyword nativeEv, if you do not know the specific name of the function or function name, it is best to conduct a fuzzy search.
Do not search do not know, a search shocked, there are many functions that receive native messages, which are not shown below.
There are a total of the following functions in the above figure
FilterNativeEvent: callback function for installing event filters
InstallNativeEventFilter: install the event filter, the callback function is the fourth function
NativeEvent: window native event callback
NativeEventFilter: event filter callback function, installed using method 2
Everyone will be a little confused to see here, it seems that they are all the same! In fact, it is not, but there are others. Interested students can take a look at several related articles I have written before, all of which use receiving global windows messages to achieve the first pass function, specifically using the above method 2 + method 4 to complete.
Custom QLineEdit right-click menu for Qt
Qt captures global windows messages
Qt's stock component-stock search-supports preview of search results, mouse and keyboard operations
In addition to matching method 2 and method 4, method 1 and method 2 can also be used together, implying that method 2 is based on the event filter, and method 1 and method 4 are just callback handling interfaces for the event filter.
Why do you say so, you can verify, or open the help document, we enter the keyword installNativeEventFilter, enter will find that the event filter can be installed on two objects, one is the well-known QCoreApplication, the other looks like a global abstract event dispatcher. Congratulations, you are right. Both of these objects are very powerful and can give priority to the global events of Qt.
In this article, we just want to achieve the jitter of a modal form, so there is no need for overkill, we can use the nativeEvent function of QWidget, and we can also achieve our goal.
The general direction has been set, so what are you waiting for?
Open vs and create a new demo. Kuang Kuang, it's just a meal.
I was overjoyed to find that it really worked.
The following is the core code of the implementation, because it is demo, so the writing is relatively rough, we had better standardize the code when writing into the project.
Bool XXX::nativeEvent (const QByteArray & eventType, void * message, long * result) {if ("windows_generic_MSG" = = eventType) {MSG * pMsg = reinterpret_cast (message); if (pMsg- > message = = WM_NCACTIVATE) {bool active = (bool) (pMsg- > wParam); if (active) {setStyleSheet ("border:2 solid blue;background:gray;") } else {setStyleSheet ("border:2 solid red;background:gray;");} style ()-> unpolish (this); style ()-> polish (this);}} return QDialog::nativeEvent (eventType, message, result);}
Focus on
Here also need to say that some students according to the document operation, debugging time code also went to the relevant position, but found no effect, and then began to doubt life.
Here the blogger focuses on several possible mistakes.
Our modal form must specify who the modal parent form is.
Be sure to set the Qt::Dialog property on the form
The second point is very critical, many students do not set this property, resulting in the loss of effect.
After reading this article, I believe you have a certain understanding of "Qt borderless form how to simulate modal form jitter effect". If you want to know more about it, welcome to follow the industry information channel, thank you for reading!
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.