QT Event Processing

Source: Internet
Author: User
QT Event Processing(2011-03-29 16:05:52) reprinted
Tags: qt it Category: WORKS

Events are generated by the windowing system or QT itself, in response to the various kinds of things that happen. When the user presses or releases the keys on the keyboard or mouse, a key can be generated

Disk or mouse events, when a window is first displayed, a drawing event is generated to tell the window that it needs to redraw itself, making the window visible. Most events are

Generated as a response to a user action, but there are some exceptions, such as timer events, which are generated independently by the system.
In general, when using widgets, QT widgets often send a signal, which is useful, but when we need to write our own custom window

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

Clicked () signals tend to be more focused, with little concern for the underlying mouse events or keyboard events that contributed to the signal being emitted. But what we are going to achieve is a similar to Qpushbutton, or that we

To implement a Qpushbutton, it is necessary to write code that handles the mouse and keyboard events, and to emit the clicked () signal when needed. You can think of the signal as life.

An incident is a message, and an officer on the battlefield waits for the exact message, and then orders it according to the message.
The difference between the signal and the event is that the event is lower than the signal, and if a signal corresponds to more than one slot, the transmission of the signal is unordered, and the transmission of the event is orderly. In fact, in many

Thread implementations also rely on the event-handling mechanism with QT. Above we have a preliminary understanding of the incident. Let's continue with a more detailed understanding of the event.
In QT, events are encapsulated into objects, and all events inherit from the abstract class qevent. Next, let's talk about who will produce, distribute, accept, and handle events in QT:
1. Who will generate the event: The easiest thing to think about is our input device, such as the keyboard, the mouse-generated event Keypressevent,keyreleaseevent,mousepressevent event (he

are encapsulated into qmouseevent and qkeyevent), these events come from the underlying operating system, and they can notify the QT event processing system asynchronously, and the text will be carefully followed. Of course Qt himself

There are also many events, such as Qobject::starttimer () that trigger qtimerevent. The user's program can also customize the events themselves.
2. Who will accept and deal with the event: the answer is Qobject. The Qobject class is the heart of the entire QT object model in the anatomy of the introspection mechanism of QT, and the event handling mechanism is Qobject

One of three responsibilities (memory management, introspection (intropection) and event handling). Any object that wants to accept and handle an event must inherit from Qobject, and you can choose to re-qobject::event

() The processing power of the function or event is given to the parent class.
3. Who will be responsible for distributing the event: for the Non-gui QT program, the qcoreapplication is responsible for distributing qevent to Qobject sub-class-receiver. For QT GUI programs, the

Qapplication to be responsible.
In Qt, an event is an instance of the Qevent subclass. There are more than 100 types of events for QT processing
Qevent::none 0 Not an event.
Qevent::accessibilitydescription used to query Accessibility description texts (qaccessibleevent).
QEVENT::ACCESSIBILITYHELP 119 used to query accessibility Help texts (qaccessibleevent).
Qevent::accessibilityprepare accessibility information is requested.
qevent::actionadded A New action has been added (qactionevent).
Qevent::actionchanged 113 An action has been changed (qactionevent).
Qevent::actionremoved-A action has been removed (qactionevent).
Qevent::activationchange A widget ' s top-level window activation state has changed.
Qevent::applicationactivate 121 The application have been made available to the user.
Qevent::applicationactivated Applicationactivate This enum has been deprecated. Use

Applicationactivate instead.
Qevent::applicationdeactivate 122 The application has a been suspended, and is a unavailable to the user.
Qevent::applicationfontchange The default application font has changed.
Qevent::applicationlayoutdirectionchange PNS The default application layout direction has changed.
Qevent::applicationpalettechange The default application palette has changed.
Qevent::applicationwindowiconchange the application ' s icon has changed.
Qevent::childadded, an object, gets a child (qchildevent).
Qevent::childinserted A object gets a child (qchildevent). Qt3support only, use childadded

instead.
qevent::childpolished A widget child gets polished (qchildevent).
Qevent::childremoved loses a child (qchildevent).
Qevent::clipboard the Clipboard contents has changed (qclipboardevent).
Qevent::close Widget was closed (qcloseevent).
Qevent::closesoftwareinputpanel A Widget wants to close the software Input Panel (SIP).
Qevent::contentsrectchange 178 The margins of the widget ' s content rect changed.
Qevent::contextmenu, Qcontextmenuevent, and the Context popup menu.
Qevent::cursorchange 183 The widget ' s cursor has changed.
Qevent::D Eferreddelete, the object would be deleted after it had cleaned up.
Qevent::D ragenter the cursor enters a widget during a drag and drop operation

(qdragenterevent).
Qevent::D ragleave, the cursor leaves a widget during a drag and drop operation

(qdragleaveevent).
Qevent::D ragmove A Drag and drop operation is in progress (qdragmoveevent).
Qevent::D rop A Drag and Drop operation is completed (qdropevent).
Qevent::enabledchange 98 Widget ' s enabled state has changed.
Qevent::enter Mouse enters widget ' s boundaries.
Qevent::entereditfocus a editor widget gains focus for editing.
Qevent::enterwhatsthismode 124 Send to toplevel widgets then the application enters "What's this?" mode.
Qevent::fileopen the File Open request (qfileopenevent).
Qevent::focusin 8 Widget gains keyboard focus (qfocusevent).
Qevent::focusout 9 Widget loses keyboard focus (qfocusevent).
Qevent::fontchange the 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 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 Widget was hidden (qhideevent).
Qevent::hidetoparent A Child widget has been hidden.
Qevent::hoverenter 127 the mouse cursor enters a hover widget (qhoverevent).
Qevent::hoverleave the mouse cursor leaves a hover widget (qhoverevent).
Qevent::hovermove 129 the mouse cursor moves inside a hover widget (qhoverevent).
Qevent::icondrag The main icon of a window has been dragged away (qicondragevent).
Qevent::icontextchange 101 Widget ' s icon text has been changed.
Qevent::inputmethod an input method is being used (qinputmethodevent).
Qevent::keypress 6 Key Press (qkeyevent).
Qevent::keyrelease 7 Key Release (qkeyevent).
Qevent::languagechange the application translation changed.
Qevent::layoutdirectionchange the direction of layouts changed.
Qevent::layoutrequest Widget layout needs to be redone.
Qevent::leave Mouse leaves widget ' s boundaries.
Qevent::leaveeditfocus 151 an editor widgets loses focus for editing.
Qevent::leavewhatsthismode Send to TopLevel widgets when the application leaves "What's this?" mode.
Qevent::localechange 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 widgets sizes (Mac OS X only).
qevent::menubarupdated 153 The window ' s menu bar has been updated.
Qevent::metacall 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 the Widget's position changed (qmoveevent).
Qevent::P aint screen update necessary (qpaintevent).
Qevent::P alettechange Palette of the widget changed.
Qevent::P arentabouttochange 131 The widget, parent is on change.
Qevent::P Arentchange The widget parent has changed.
Qevent::P olish the widget is polished.
Qevent::P olishrequest The widget should be polished.
Qevent::querywhatsthis 123 The widget should accept the event if it has a "what's this?" Help.
Qevent::requestsoftwareinputpanel 199 a widget wants to open A software Input Panel (SIP).
Qevent::resize Widget ' s size changed (qresizeevent).
Qevent::shortcut 117 Key Press in the child for Shortcut key handling (qshortcutevent).
Qevent::shortcutoverride-Key press in child, for overriding shortcut key handling (qkeyevent).
Qevent::show Widget is shown on screen (qshowevent).
Qevent::showtoparent A Child widget has been shown.
Qevent::sockact Socket activated, used to implement Qsocketnotifier.
Qevent::statemachinesignal

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.