QEvent Class

The QEvent class is the base class of all event classes. Event objects contain event parameters. More...

Public Types

enum Type { None, ActionAdded, ActionChanged, ActionRemoved, ActivationChange, …, MaxUser }

Properties

Public Functions

QEvent(QEvent::Type type)
virtual ~QEvent()
void accept()
(since 6.0) virtual QEvent *clone() const
void ignore()
bool isAccepted() const
(since 6.0) bool isInputEvent() const
(since 6.0) bool isPointerEvent() const
(since 6.0) bool isSinglePointEvent() const
virtual void setAccepted(bool accepted)
bool spontaneous() const
QEvent::Type type() const

Static Public Members

int registerEventType(int hint = -1)

Detailed Description

Qt's main event loop (QCoreApplication::exec()) fetches native window system events from the event queue, translates them into QEvents, and sends the translated events to QObjects.

In general, events come from the underlying window system (spontaneous() returns true), but it is also possible to manually send events using QCoreApplication::sendEvent() and QCoreApplication::postEvent() (spontaneous() returns false).

QObjects receive events by having their QObject::event() function called. The function can be reimplemented in subclasses to customize event handling and add additional event types; QWidget::event() is a notable example. By default, events are dispatched to event handlers like QObject::timerEvent() and QWidget::mouseMoveEvent(). QObject::installEventFilter() allows an object to intercept events destined for another object.

The basic QEvent contains only an event type parameter and an "accept" flag. The accept flag set with accept(), and cleared with ignore(). It is set by default, but don't rely on this as subclasses may choose to clear it in their constructor.

Subclasses of QEvent contain additional parameters that describe the particular event.

See also QObject::event(), QObject::installEventFilter(), QCoreApplication::sendEvent(), QCoreApplication::postEvent(), and QCoreApplication::processEvents().

Member Type Documentation

enum QEvent::Type

This enum type defines the valid event types in Qt. The event types and the specialized classes for each type are as follows:

ConstantValueDescription
QEvent::None0Not an event.
QEvent::ActionAdded114A new action has been added (QActionEvent).
QEvent::ActionChanged113An action has been changed (QActionEvent).
QEvent::ActionRemoved115An action has been removed (QActionEvent).
QEvent::ActivationChange99A widget's top-level window activation state has changed.
QEvent::ApplicationActivate121This enum has been deprecated. Use ApplicationStateChange instead.
QEvent::ApplicationActivatedApplicationActivateThis enum has been deprecated. Use ApplicationStateChange instead.
QEvent::ApplicationDeactivate122This enum has been deprecated. Use ApplicationStateChange instead.
QEvent::ApplicationFontChange36The default application font has changed.
QEvent::ApplicationLayoutDirectionChange37The default application layout direction has changed.
QEvent::ApplicationPaletteChange38The default application palette has changed.
QEvent::ApplicationStateChange214The state of the application has changed.
QEvent::ApplicationWindowIconChange35The application's icon has changed.
QEvent::ChildAdded68An object gets a child (QChildEvent).
QEvent::ChildPolished69A widget child gets polished (QChildEvent).
QEvent::ChildRemoved71An object loses a child (QChildEvent).
QEvent::ChildWindowAdded (since Qt 6.7)223A child window was added to the window.
QEvent::ChildWindowRemoved (since Qt 6.7)224A child window was removed from the window.
QEvent::Clipboard40The clipboard contents have changed.
QEvent::Close19Widget was closed (QCloseEvent).
QEvent::CloseSoftwareInputPanel200A widget wants to close the software input panel (SIP).
QEvent::ContentsRectChange178The margins of the widget's content rect changed.
QEvent::ContextMenu82Context popup menu (QContextMenuEvent).
QEvent::CursorChange183The widget's cursor has changed.
QEvent::DeferredDelete52The object will be deleted after it has cleaned up (QDeferredDeleteEvent)
QEvent::DevicePixelRatioChange (since Qt 6.6)222The devicePixelRatio has changed for this widget's or window's underlying backing store.
QEvent::DragEnter60The cursor enters a widget during a drag and drop operation (QDragEnterEvent).
QEvent::DragLeave62The cursor leaves a widget during a drag and drop operation (QDragLeaveEvent).
QEvent::DragMove61A drag and drop operation is in progress (QDragMoveEvent).
QEvent::Drop63A drag and drop operation is completed (QDropEvent).
QEvent::DynamicPropertyChange170A dynamic property was added, changed, or removed from the object.
QEvent::EnabledChange98Widget's enabled state has changed.
QEvent::Enter10Mouse enters widget's boundaries (QEnterEvent).
QEvent::EnterEditFocus150An editor widget gains focus for editing. QT_KEYPAD_NAVIGATION must be defined.
QEvent::EnterWhatsThisMode124Send to toplevel widgets when the application enters "What's This?" mode.
QEvent::Expose206Sent to a window when its on-screen contents are invalidated and need to be flushed from the backing store.
QEvent::FileOpen116File open request (QFileOpenEvent).
QEvent::FocusIn8Widget or Window gains keyboard focus (QFocusEvent).
QEvent::FocusOut9Widget or Window loses keyboard focus (QFocusEvent).
QEvent::FocusAboutToChange23Widget or Window focus is about to change (QFocusEvent)
QEvent::FontChange97Widget's font has changed.
QEvent::Gesture198A gesture was triggered (QGestureEvent).
QEvent::GestureOverride202A gesture override was triggered (QGestureEvent).
QEvent::GrabKeyboard188Item gains keyboard grab (QGraphicsItem only).
QEvent::GrabMouse186Item gains mouse grab (QGraphicsItem only).
QEvent::GraphicsSceneContextMenu159Context popup menu over a graphics scene (QGraphicsSceneContextMenuEvent).
QEvent::GraphicsSceneDragEnter164The cursor enters a graphics scene during a drag and drop operation (QGraphicsSceneDragDropEvent).
QEvent::GraphicsSceneDragLeave166The cursor leaves a graphics scene during a drag and drop operation (QGraphicsSceneDragDropEvent).
QEvent::GraphicsSceneDragMove165A drag and drop operation is in progress over a scene (QGraphicsSceneDragDropEvent).
QEvent::GraphicsSceneDrop167A drag and drop operation is completed over a scene (QGraphicsSceneDragDropEvent).
QEvent::GraphicsSceneHelp163The user requests help for a graphics scene (QHelpEvent).
QEvent::GraphicsSceneHoverEnter160The mouse cursor enters a hover item in a graphics scene (QGraphicsSceneHoverEvent).
QEvent::GraphicsSceneHoverLeave162The mouse cursor leaves a hover item in a graphics scene (QGraphicsSceneHoverEvent).
QEvent::GraphicsSceneHoverMove161The mouse cursor moves inside a hover item in a graphics scene (QGraphicsSceneHoverEvent).
QEvent::GraphicsSceneMouseDoubleClick158Mouse press again (double click) in a graphics scene (QGraphicsSceneMouseEvent).
QEvent::GraphicsSceneMouseMove155Move mouse in a graphics scene (QGraphicsSceneMouseEvent).
QEvent::GraphicsSceneMousePress156Mouse press in a graphics scene (QGraphicsSceneMouseEvent).
QEvent::GraphicsSceneMouseRelease157Mouse release in a graphics scene (QGraphicsSceneMouseEvent).
QEvent::GraphicsSceneMove182Widget was moved (QGraphicsSceneMoveEvent).
QEvent::GraphicsSceneResize181Widget was resized (QGraphicsSceneResizeEvent).
QEvent::GraphicsSceneWheel168Mouse wheel rolled in a graphics scene (QGraphicsSceneWheelEvent).
QEvent::GraphicsSceneLeave220The cursor leaves a graphics scene (QGraphicsSceneWheelEvent).
QEvent::Hide18Widget was hidden (QHideEvent).
QEvent::HideToParent27A child widget has been hidden.
QEvent::HoverEnter127The mouse cursor enters a hover widget (QHoverEvent).
QEvent::HoverLeave128The mouse cursor leaves a hover widget (QHoverEvent).
QEvent::HoverMove129The mouse cursor moves inside a hover widget (QHoverEvent).
QEvent::IconDrag96The main icon of a window has been dragged away (QIconDragEvent).
QEvent::IconTextChange101Widget's icon text has been changed. (Deprecated)
QEvent::InputMethod83An input method is being used (QInputMethodEvent).
QEvent::InputMethodQuery207A input method query event (QInputMethodQueryEvent)
QEvent::KeyboardLayoutChange169The keyboard layout has changed.
QEvent::KeyPress6Key press (QKeyEvent).
QEvent::KeyRelease7Key release (QKeyEvent).
QEvent::LanguageChange89The application translation changed.
QEvent::LayoutDirectionChange90The direction of layouts changed.
QEvent::LayoutRequest76Widget layout needs to be redone.
QEvent::Leave11Mouse leaves widget's boundaries.
QEvent::LeaveEditFocus151An editor widget loses focus for editing. QT_KEYPAD_NAVIGATION must be defined.
QEvent::LeaveWhatsThisMode125Send to toplevel widgets when the application leaves "What's This?" mode.
QEvent::LocaleChange88The system locale has changed.
QEvent::NonClientAreaMouseButtonDblClick176A mouse double click occurred outside the client area (QMouseEvent).
QEvent::NonClientAreaMouseButtonPress174A mouse button press occurred outside the client area (QMouseEvent).
QEvent::NonClientAreaMouseButtonRelease175A mouse button release occurred outside the client area (QMouseEvent).
QEvent::NonClientAreaMouseMove173A mouse move occurred outside the client area (QMouseEvent).
QEvent::MacSizeChange177The user changed his widget sizes (macOS only).
QEvent::MetaCall43An asynchronous method invocation via QMetaObject::invokeMethod().
QEvent::ModifiedChange102Widgets modification state has been changed.
QEvent::MouseButtonDblClick4Mouse press again (QMouseEvent).
QEvent::MouseButtonPress2Mouse press (QMouseEvent).
QEvent::MouseButtonRelease3Mouse release (QMouseEvent).
QEvent::MouseMove5Mouse move (QMouseEvent).
QEvent::MouseTrackingChange109The mouse tracking state has changed.
QEvent::Move13Widget's position changed (QMoveEvent).
QEvent::NativeGesture197The system has detected a gesture (QNativeGestureEvent).
QEvent::OrientationChange208The screens orientation has changes (QScreenOrientationChangeEvent).
QEvent::Paint12Screen update necessary (QPaintEvent).
QEvent::PaletteChange39Palette of the widget changed.
QEvent::ParentAboutToChange131The object parent is about to change. Only sent to some object types, such as QWidget.
QEvent::ParentChange21The object parent has changed. Only sent to some object types, such as QWidget.
QEvent::ParentWindowAboutToChange (since Qt 6.7)225The parent window is about to change.
QEvent::ParentWindowChange (since Qt 6.7)226The parent window has changed.
QEvent::PlatformPanel212A platform specific panel has been requested.
QEvent::PlatformSurface217A native platform surface has been created or is about to be destroyed (QPlatformSurfaceEvent).
QEvent::Polish75The widget is polished.
QEvent::PolishRequest74The widget should be polished.
QEvent::QueryWhatsThis123The widget should accept the event if it has "What's This?" help (QHelpEvent).
QEvent::Quit20The application has exited.
QEvent::ReadOnlyChange (since Qt 5.4)106Widget's read-only state has changed.
QEvent::RequestSoftwareInputPanel199A widget wants to open a software input panel (SIP).
QEvent::Resize14Widget's size changed (QResizeEvent).
QEvent::ScrollPrepare204The object needs to fill in its geometry information (QScrollPrepareEvent).
QEvent::Scroll205The object needs to scroll to the supplied position (QScrollEvent).
QEvent::Shortcut117Key press in child for shortcut key handling (QShortcutEvent).
QEvent::ShortcutOverride51Key press in child, for overriding shortcut key handling (QKeyEvent). When a shortcut is about to trigger, ShortcutOverride is sent to the active window. This allows clients (e.g. widgets) to signal that they will handle the shortcut themselves, by accepting the event. If the shortcut override is accepted, the event is delivered as a normal key press to the focus widget. Otherwise, it triggers the shortcut action, if one exists.
QEvent::Show17Widget was shown on screen (QShowEvent).
QEvent::ShowToParent26A child widget has been shown.
QEvent::SockAct50Socket activated, used to implement QSocketNotifier.
QEvent::StateMachineSignal192A signal delivered to a state machine (QStateMachine::SignalEvent).
QEvent::StateMachineWrapped193The event is a wrapper for, i.e., contains, another event (QStateMachine::WrappedEvent).
QEvent::StatusTip112A status tip is requested (QStatusTipEvent).
QEvent::StyleChange100Widget's style has been changed.
QEvent::TabletMove87Wacom tablet move (QTabletEvent).
QEvent::TabletPress92Wacom tablet press (QTabletEvent).
QEvent::TabletRelease93Wacom tablet release (QTabletEvent).
QEvent::TabletEnterProximity171Wacom tablet enter proximity event (QTabletEvent), sent to QApplication.
QEvent::TabletLeaveProximity172Wacom tablet leave proximity event (QTabletEvent), sent to QApplication.
QEvent::TabletTrackingChange (since Qt 5.9)219The Wacom tablet tracking state has changed.
QEvent::ThreadChange22The object is moved to another thread. This is the last event sent to this object in the previous thread. See QObject::moveToThread().
QEvent::Timer1Regular timer events (QTimerEvent).
QEvent::ToolBarChange120The toolbar button is toggled on macOS.
QEvent::ToolTip110A tooltip was requested (QHelpEvent).
QEvent::ToolTipChange184The widget's tooltip has changed.
QEvent::TouchBegin194Beginning of a sequence of touch-screen or track-pad events (QTouchEvent).
QEvent::TouchCancel209Cancellation of touch-event sequence (QTouchEvent).
QEvent::TouchEnd196End of touch-event sequence (QTouchEvent).
QEvent::TouchUpdate195Touch-screen event (QTouchEvent).
QEvent::UngrabKeyboard189Item loses keyboard grab (QGraphicsItem only).
QEvent::UngrabMouse187Item loses mouse grab (QGraphicsItem, QQuickItem).
QEvent::UpdateLater78The widget should be queued to be repainted at a later time.
QEvent::UpdateRequest77The widget should be repainted.
QEvent::WhatsThis111The widget should reveal "What's This?" help (QHelpEvent).
QEvent::WhatsThisClicked118A link in a widget's "What's This?" help was clicked.
QEvent::Wheel31Mouse wheel rolled (QWheelEvent).
QEvent::WinEventAct132A Windows-specific activation event has occurred.
QEvent::WindowActivate24Window was activated.
QEvent::WindowBlocked103The window is blocked by a modal dialog.
QEvent::WindowDeactivate25Window was deactivated.
QEvent::WindowIconChange34The window's icon has changed.
QEvent::WindowStateChange105The window's state (minimized, maximized or full-screen) has changed (QWindowStateChangeEvent).
QEvent::WindowTitleChange33The window title has changed.
QEvent::WindowUnblocked104The window is unblocked after a modal dialog exited.
QEvent::WinIdChange203The window system identifier for this native widget has changed.
QEvent::ZOrderChange126The widget's z-order has changed. This event is never sent to top level windows.

User events should have values between User and MaxUser:

ConstantValueDescription
QEvent::User1000User-defined event.
QEvent::MaxUser65535Last user event ID.

For convenience, you can use the registerEventType() function to register and reserve a custom event type for your application. Doing so will allow you to avoid accidentally re-using a custom event type already in use elsewhere in your application.

Property Documentation

accepted : bool

This property holds the accept flag of the event object.

Setting the accept parameter indicates that the event receiver wants the event. Unwanted events might be propagated to the parent widget. By default, isAccepted() is set to true, but don't rely on this as subclasses may choose to clear it in their constructor.

For convenience, the accept flag can also be set with accept(), and cleared with ignore().

Note: Accepting a QPointerEvent implicitly accepts all the points that the event carries.

Access functions:

bool isAccepted() const
virtual void setAccepted(bool accepted)

Member Function Documentation

[explicit] QEvent::QEvent(QEvent::Type type)

Constructs an event object of type type.

[virtual noexcept] QEvent::~QEvent()

Destroys the event. If it was posted, it will be removed from the list of events to be posted.

void QEvent::accept()

Sets the accept flag of the event object, the equivalent of calling setAccepted(true).

Setting the accept parameter indicates that the event receiver wants the event. Unwanted events might be propagated to the parent widget.

See also ignore().

[virtual, since 6.0] QEvent *QEvent::clone() const

Creates and returns an identical copy of this event.

This function was introduced in Qt 6.0.

void QEvent::ignore()

Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).

Clearing the accept parameter indicates that the event receiver does not want the event. Unwanted events might be propagated to the parent widget.

See also accept().

[noexcept, since 6.0] bool QEvent::isInputEvent() const

Returns true if the event object is a QInputEvent or one of its subclasses.

This function was introduced in Qt 6.0.

[noexcept, since 6.0] bool QEvent::isPointerEvent() const

Returns true if the event object is a QPointerEvent or one of its subclasses.

This function was introduced in Qt 6.0.

[noexcept, since 6.0] bool QEvent::isSinglePointEvent() const

Returns true if the event object is a subclass of QSinglePointEvent.

This function was introduced in Qt 6.0.

[static noexcept] int QEvent::registerEventType(int hint = -1)

Registers and returns a custom event type. The hint provided will be used if it is available, otherwise it will return a value between QEvent::User and QEvent::MaxUser that has not yet been registered. The hint is ignored if its value is not between QEvent::User and QEvent::MaxUser.

Returns -1 if all available values are already taken or the program is shutting down.

Note: This function is thread-safe.

bool QEvent::spontaneous() const

Returns true if the event originated outside the application (a system event); otherwise returns false.

QEvent::Type QEvent::type() const

Returns the event type.