QtMediumEventThe processing process is the content to be introduced in this article, mainly to understandEvent. InQt/Embedded, mouseEventFrom touch screen devices. After using select to read data from the touch screen device, sampling is performed and the pressure reaches a certain threshold.) After processing some sampling points, a coordinate point is obtained for a physical device, then, use the sendEvent of QCoreApplication to live postEvent and send it out.Event.
First, QCoreApplication: notify passes the event directly to the receiver. Implement it again to intercept all the events to be handled by the system.
Next, you can install an event filter for the application's instance qApp after using notify to notify the receiver to process events within the application.
Third, after the event is processed by the application, it reaches the QObject event filter list, installs the event filter for the recipients, and only processes the events sent to them.
Fourth, after the above processing, the event reaches the QObject event function. This function processes events sent to itself. For example, in QWidget, it distributes events to its own Handler according to the event type, such as MouseReleaseEvent and KeyPressEvent.
Finally, event handler is used to process different types of events. This is often used, and it only processes its own events.
The process is as follows:
- Bool QCoreApplication: notify (
- QObject
- * Cycler, QEvent
- * Event
- )
- -> QApp
- Of
- Event filters-> object
- Of
- Event filter-> object
- Event () ()
- Function> object
- Of
- Event handler
-
In the preceding process, true indicates that the event is aborted, and false indicates that the event is resumed.
Parent-Child form transfer relationship:
For the QWidget that forms the parent-child relationship, the event is first passed to the child. After the child form is ignore, the event is passed to the parent form. If it is accept, the upload is terminated.
Delivery. If you want to intercept the event sent to the child form in the parent form container, you can use QObject: findChildren to find the child list and install the event filter for it. For example, reload the eventfilter function and install it. Of course, you can also enable the parent form to continue processing after ignore in the inherited subclass event handler, but this is not an interception.
Note: According to the Qt document, the installed event filter does not support objects executed in another thread.
Application instance:
FileBrowser contains multiple QPushButton and a QFrame. QFrame contains a QStackedWidget, which contains a QListView and a QTreeView. The two widgets are ). Filebrowser implements eventFilter and installs them in the FileBrowser constructor:
- this->installEventFilter(this);
- listView->installEventFilter(this);//not work,why?
- treeView->installEventFilter(this);//not work,why?
- QList<QPushButton*> allButtons = this->findChildren<QPushButton *>();
- foreach(QPushButton* button, allButtons)
- button->installEventFilter(this);
The running result is as follows:
- obj name1:FileBrowserListView, type: 8
- event filter: pid=6273 tid=-1208457520
- ListView::mouseReleaseEvent: pid=6273 tid=-1208457520
Problem:
Output result in eventfilter of the first two actions: It indicates that the event type sent to ListView is 8 and the FocusIn event is intercepted ). The third row is the output of event handler of listView. It can process mouse and release events, but event filter does not capture it, but can capture the gains and losses of focus. The output thread number is the same.
Why?EventFilter cannot capture mouse clicks on two viewsEventBut you can obtain otherEventFor example, what about FocusIn and FocusOut?
The output log Code is:
- #include<unistd.h>
- //#include<sys/types.h>
- #include <pthread.h>
- ...
- fprintf(stderr, "ListView::mouseReleaseEvent: pid=%d tid=%d\n",::getpid(), (unsigned int)::pthread_self()/*::gettid()*/);
Summary: DetailsQtMediumEventThe content of the processing process has been introduced. I hope this article will help you!