Qt events and Signals

Source: Internet
Author: User

Let's take a closer look at the differences between events and signals. From the perspective of our needs, we only need to be able to register events or signal response functions, you can be notified when an event or signal is generated. However, the difference is that the return value of the event processing function is meaningful. We need to determine whether to continue the Event Processing Based on the returned value. For example, in QT, if the event processing function returns true, the event processing is completed, and qapplication processes the next event. If false is returned, then, the event dispatch function continues to look up for the next registration method that can handle the event. The Return Value of the signal processing function is meaningless for the signal dispatcher.

Another issue that needs our attention is the priority issue during event and signal processing. In QT, events are related to the window, so the Event Callback starts from the current window and is distributed up at the first level until a window returns true, process the event. Signal processing is relatively simple, and there is no order by default. If you need a clear order, you can specify the slot position when the signal is registered. In QT, events are maintained using an event queue. If a new event is generated during event processing, the new event is added to the end of the queue, after the current event is processed, qapplication takes the next event from the queue header for processing. The signal processing method is somewhat different. The signal processing method calls back immediately, that is, after a signal is generated, all the slots registered above will be called back immediately. In this way, a recursive call problem occurs. For example, another signal is generated in a signal processor, which makes the signal processing expand like a tree.

Events are generated by the window system or QT itself to respond to various events. When you press or release a button on the keyboard or mouse, a key is generated.

Disk or mouse event. When a window is displayed for the first time, a draw event is generated to indicate that the window needs to be re-drawn, so that the window can be visible. Most events are

As a response to user actions, but there are also some exceptions. For example, a timer event is generated independently by the system.
In general, when using Windows Components, QT Windows components usually send signals, which are also very useful, but when we need to write our own custom windows

When we want to change the behavior of the existing QT widget, the event becomes very useful. For example, when we use qpushbutton

The clicked () signal is often more concerned, but seldom concerned with the underlying mouse events or Keyboard Events that contribute to the signal. But what we want to achieve is a similar to qpushbutton, or we

To implement a qpushbutton, you need to write code to handle mouse and keyboard events. When necessary, you also need to transmit clicked () signals. The signal is life.

An event is a message. A military officer on the battlefield can issue a command based on the message only after the accurate message is sent.
The difference between a signal and an event is that an event is more underlying than a signal. If a signal corresponds to multiple slots, the signal transmission is disordered, and the event transmission is ordered. In fact, there are many

The implementation of threads also depends on the event processing mechanism of QT. We have a preliminary understanding of the incident. Next we will continue to have a more detailed understanding of the event.
In QT, events are encapsulated into objects, and all events are inherited from the abstract class qevent. Next we will talk about who generates, distributes, accepts, and processes events in Qt in sequence:
1. Who will generate events: the most likely thing to think of is the keypressevent, keyreleaseevent, and mousepressevent events generated by the keyboard and mouse.

Are encapsulated into qmouseevent and qkeyevent), these events come from the underlying operating system, they can notify the QT event processing system asynchronously, which will be discussed in detail later. Of course, QT itself

There will also be many events, such as qobject: starttimer () will trigger qtimerevent. User Programs can also customize events.
2. Who will accept and handle the event? The answer is qobject. The article on the introspection Mechanism Analysis of QT has introduced that the qobject class is the heart of the entire QT object model, and the event processing mechanism is qobject.

One of the three major responsibilities (memory management, intropection and event processing. Any object that wants to accept and process events must inherit from qobject. You can select "re-qobject: Event ".

() Grant the processing permission of a function or event to the parent class.
3. Who is responsible for event distribution: for non-Gui QT programs, qcoreapplication is responsible for distributing qevents to the sub-class-aggreger of qobject. For qt gui programs

Qapplication.
In QT, an event is an instance of the qevent subclass. Qt processes over one hundred event types
Qevent: None 0 not an event.
Qevent: accessibilitydescription 130 used to query accessibility description texts (qaccessibleevent ).
Qevent: accessibilityhelp 119 used to query accessibility help texts (qaccessibleevent ).
Qevent: accessibilityprepare 86 accessibility information is requested.
Qevent: actionadded 114 a new action has been added (qactionevent ).
Qevent: actionchanged 113 an action has been changed (qactionevent ).
Qevent: actionremoved 115 an action has been removed (qactionevent ).
Qevent: activationchange 99 a widget's top-level window activation state has changed.
Qevent: applicationactivate 121 the application has been made available to the user.
Qevent: applicationactivated applicationactivate this Enum has been deprecated. Use

Applicationactivate instead.
Qevent: applicationdeactivate 122 the application has been suincluded, and is unavailable to the user.
Qevent: applicationfontchange 36 the Default Application font has changed.
Qevent: applicationlayoutdirechange 37 the Default Application layout direction has changed.
Qevent: applicationpalettechange 38 the Default Application palette has changed.
Qevent: applicationappswiconchange 35 the application's icon has changed.
Qevent: childadded 68 an object gets a child (qchildevent ).
Qevent: childinserted 70 an object gets a child (qchildevent). qt3support only, use childadded

Instead.
Qevent: childpolished 69 a widget child gets polished (qchildevent ).
Qevent: childremoved 71 an object loses a child (qchildevent ).
Qevent: clipboard 40 the clipboard contents have changed (qclipboardevent ).
Qevent: Close 19 widget was closed (qcloseevent ).
Qevent: closesoftwareinputpanel 200 a widget wants to close the software Input Panel (SIP ).
Qevent: contentsrectchange 178 the margins of the widget's content rect changed.
Qevent: contextmenu 82 context popup menu (qcontextmenuevent ).
Qevent: cursorchange 183 the widget's cursor has changed.
Qevent: deferreddelete 52 the object will be deleted after it has cleaned up.
Qevent: dragenter 60 the cursor enters a widget during a drag and drop operation

(Qdragenterevent ).
Qevent: dragleave 62 the cursor leaves a widget during a drag and drop operation

(Qdragleaveevent ).
Qevent: dragmove 61 A Drag and Drop operation is in progress (qdragmoveevent ).
Qevent: Drop 63 A Drag and Drop operation is completed (qdropevent ).
Qevent: enabledchange 98 widget's enabled state has changed.
Qevent: enter 10 mouse enters widget's boundaries.
Qevent: entereditfocus 150 an editor widget gains focus for editing.
Qevent: enterwhatsthismode 124 send to toplevel widgets when the application enters "What's this? "Mode.
Qevent: fileopen116 file open request (qfileopenevent ).
Qevent: focusin 8 widget gains keyboard focus (qfocusevent ).
Qevent: focusout 9 widget loses keyboard focus (qfocusevent ).
Qevent: fontchange 97 widget's font has changed.
Qevent: grabkeyboard 188 Item gains keyboard grab (qgraphicsitem only ).
Qevent: grabmouse 186 Item gains mouse grab (qgraphicsitem only ).
Qevent: graphicsscenecontextmenu 159 context popup menu over a graphics scene (qgraphicsscenecontextmenuevent ).
Qevent: graphicsscenedragenter 164 the cursor enters a graphics scene during a drag and drop operation

(Qgraphicsscenedragdropevent ).
Qevent: graphicsscenedragleave 166 The cursor leaves a graphics scene during a drag and drop operation

(Qgraphicsscenedragdropevent ).
Qevent: graphicsscenedragmove 165 A Drag and Drop operation is in progress over a scene

(Qgraphicsscenedragdropevent ).
Qevent: graphicsscenedrop 167 A Drag and Drop operation is completed over a scene

(Qgraphicsscenedragdropevent ).
Qevent: graphicsscenehelp 163 the user requests help for a graphics scene (qhelpevent ).
Qevent: graphicsscenehoverenter 160 the mouse cursor enters a hover item in a graphics scene

(Qgraphicsscenehoverevent ).
Qevent: graphicsscenehoverleave 162 the mouse cursor leaves a hover item in a graphics scene

(Qgraphicsscenehoverevent ).
Qevent: graphicsscenehovermove 161 the mouse cursor moves inside a hover item in a graphics scene

(Qgraphicsscenehoverevent ).
Qevent: graphicsscenemousedoubleclick 158 mouse press again (double click) in a graphics scene

(Qgraphicsscenemouseevent ).
Qevent: graphicsscenemousemove 155 Move mouse in a graphics scene (qgraphicsscenemouseevent ).
Qevent: graphicsscenemousepress 156 mouse press in a graphics scene (qgraphicsscenemouseevent ).
Qevent: graphicsscenemouserelease 157 mouse release in a graphics scene (qgraphicsscenemouseevent ).
Qevent: graphicsscenemove 182 widget was moved (qgraphicsscenemoveevent ).
Qevent: graphicssceneresize 181 widget was resized (qgraphicssceneresizeevent ).
Qevent: graphicsscenewheel 168 mouse wheel rolled in a graphics scene (qgraphicsscenewheelevent ).
Qevent: Hide 18 widget was hidden (qhideevent ).
Qevent: hidetoparent 27 A Child widget has been hidden.
Qevent: hoverenter 127 the mouse cursor enters a hover widget (qhoverevent ).
Qevent: hoverleave 128 the mouse cursor leaves a hover widget (qhoverevent ).
Qevent: hovermove 129 the mouse cursor moves inside a hover widget (qhoverevent ).
Qevent: icondrag 96 The main icon of a window has been dragged away (qicondragevent ).
Qevent: icontextchange 101 widget's icon text has been changed.
Qevent: inputmethod 83 an input method is being used (qinputmethodevent ).
Qevent: keypress 6 key press (qkeyevent ).
Qevent: keyrelease 7 key release (qkeyevent ).
Qevent: languagechange 89 The application translation changed.
Qevent: layoutdirectionchange 90 the direction of layouts changed.
Qevent: layoutrequest 76 widget layout needs to be redone.
Qevent: Leave 11 mouse leaves widget's boundaries.
Qevent: leaveeditfocus 151 an editor widget loses focus for editing.
Qevent: leavewhatsthismode 125 send to toplevel widgets when the application leaves "What's this? "Mode.
Qevent: localechange 88 the system locale has changed.
Qevent: nonclientareamousebuttondblclick 176 a mouse double click occurred outside the client area.
Qevent: nonclientareamousebuttonpress 174 a mouse button press occurred outside the client area.
Qevent: nonclientareamousebuttonrelease 175 a mouse button release occurred outside the client area.
Qevent: nonclientareamousemove 173 A mouse move occurred outside the client area.
Qevent: macsizechange 177 the user changed his widget sizes (Mac OS X only ).
Qevent: menubarupdated 153 The window's menu bar has been updated.
Qevent: metacall 43 An Asynchronous Method Invocation via qmetaobject: invokemethod ().
Qevent: modifiedchange 102 widgets modification state has been changed.
Qevent: mousebuttondblclick 4 mouse press again (qmouseevent ).
Qevent: mousebuttonpress 2 mouse Press (qmouseevent ).
Qevent: mousebuttonrelease 3 mouse release (qmouseevent ).
Qevent: mousemove 5 mouse move (qmouseevent ).
Qevent: mousetrackingchange 109 the mouse tracking State has changed.
Qevent: Move 13 widget's position changed (qmoveevent ).
Qevent: paint 12 screen update necessary (qpaintevent ).
Qevent: palettechange 39 palette of the widget changed.
Qevent: parentabouttochange 131 the widget parent is about to change.
Qevent: parentchange 21 the widget parent has changed.
Qevent: Polish 75 the widget is polished.
Qevent: polishrequest 74 the widget shocould be polished.
Qevent: querywhatsthis 123 the widget shocould accept the event if it has "What's this? "Help.
Qevent: requestsoftwareinputpanel 199 a widget wants to open a software Input Panel (SIP ).
Qevent: resize 14 widget's size changed (qresizeevent ).
Qevent: Your cut 117 key press in child for your cut key handling (q1_cutevent ).
Qevent: Your cutoverride 51 key press in child, for overriding shortcut key handling (qkeyevent ).
Qevent: Show 17 widget was shown on screen (qshowevent ).
Qevent: showtoparent 26 A Child widget has been shown.
Qevent: sockact 50 socket activated, used to implement qsocketnotifier.
Qevent: statemachinesignal 192 a signal delivered to a state machine (qstatemachine: signalevent ).
Qevent: statemachinewrapped 193 the event is a wrapper for, I. e., contains, another event

(Qstatemachine: wrappedevent ).
Qevent: statustip 112 A status tip is requested (qstatustipevent ).
Qevent: stylechange 100 widget's style has been changed.
Qevent: tabletmove 87 wacom tablet move (qtabletevent ).
Qevent: tabletpress 92 wacom tablet press (qtabletevent ).
Qevent: tabletrelease 93 wacom tablet release (qtabletevent ).
Qevent: okrequest 94 OK button in decoration pressed. supported only for Windows CE.
Qevent: tabletenterproximity 171 wacom tablet enter proximity event (qtabletevent), sent to qapplication.
Qevent: tabletleaveproximity 172 wacom tablet leave proximity event (qtabletevent), sent to qapplication.
Qevent: timer 1 Regular timer events (qtimerevent ).
Qevent: toolbarchange 120 the toolbar button is toggled on Mac OS X.
Qevent: tooltip 110 A tooltip was requested (qhelpevent ).
Qevent: tooltipchange 184 the widget's tooltip has changed.
Qevent: ungrabkeyboard 189 Item loses keyboard grab (qgraphicsitem only ).
Qevent: ungrabmouse 187 Item loses mouse grab (qgraphicsitem only ).
Qevent: updatelater 78 the widget shocould be queued to be repainted at a later time.
Qevent: updaterequest 77 the widget shocould be repainted.
Qevent: whatsthis 111 the widget shocould reveal "What's this? "Help (qhelpevent ).
Qevent: whatsthisclicked 118 a link in a widget's "What's this? "Help was clicked.
Qevent: wheel 31 mouse wheel rolled (qwheelevent ).
Qevent: wineventact 132 a Windows-specific activation event has occurred.
Qevent: windowactivate 24 window was activated.
Qevent: windowblocked 103 the window is blocked by a modal dialog.
Qevent: windowdeactivate 25 window was deactivated.
Qevent: Too wiconchange 34 the window's icon has changed.
Qevent: windowstatechange 105 the window's state (minimized, maximized or full-screen) has changed

(Qwindowstatechangeevent ).
Qevent: windowtitlechange 33 the window title has changed.
Qevent: windowunblocked 104 the window is unblocked after a modal dialog exited.
Qevent: zorderchange 126 the widget's Z-order has changed. This event is never sent to top level

Windows.
Qevent: keyboardlayoutchange 169 the keyboard layout has changed.
Qevent: dynamicpropertychange 170 a dynamic property was added, changed or removed from the object.
Qevent: touchbegin 194 beginning of a sequence of touch-screen and/or track-pad events

(Qtouchevent)
Qevent: touchupdate 195 touch-screen event (qtouchevent)
Qevent: touchend 196 end of touch-Event Sequence (qtouchevent)
Qevent: winidchange 203 The Window System identifer for this native widget has changed
Qevent: gesture 198 A gesture was triggered (qgestureevent)
Qevent: gestureoverride 202 A gesture override was triggered (qgestureevent)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.