class QEvent#

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

Inherited by: QGraphicsSceneEvent, QGraphicsSceneWheelEvent, QGraphicsSceneResizeEvent, QGraphicsSceneMoveEvent, QGraphicsSceneMouseEvent, QGraphicsSceneHoverEvent, QGraphicsSceneHelpEvent, QGraphicsSceneDragDropEvent, QGraphicsSceneContextMenuEvent, QGestureEvent, WrappedEvent, SignalEvent, QWindowStateChangeEvent, QWhatsThisClickedEvent, QToolBarChangeEvent, QStatusTipEvent, QShowEvent, QShortcutEvent, QScrollPrepareEvent, QScrollEvent, QResizeEvent, QPlatformSurfaceEvent, QPaintEvent, QMoveEvent, QInputMethodQueryEvent, QInputMethodEvent, QInputEvent, QPointerEvent, QTouchEvent, QSinglePointEvent, QWheelEvent, QTabletEvent, QNativeGestureEvent, QMouseEvent, QHoverEvent, QEnterEvent, QKeyEvent, QContextMenuEvent, QIconDragEvent, QHideEvent, QHelpEvent, QFocusEvent, QFileOpenEvent, QExposeEvent, QDropEvent, QDragMoveEvent, QDragEnterEvent, QDragLeaveEvent, QCloseEvent, QChildWindowEvent, QActionEvent, QTimerEvent, QDynamicPropertyChangeEvent, QChildEvent

Synopsis#

Methods#

Virtual methods#

Static functions#

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description#

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

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

QObjects receive events by having their 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 timerEvent() and QWidget::mouseMoveEvent(). 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.

class Type#

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

Constant

Description

QEvent.None

Not an event.

QEvent.ActionAdded

A new action has been added (QActionEvent).

QEvent.ActionChanged

An action has been changed (QActionEvent).

QEvent.ActionRemoved

An action has been removed (QActionEvent).

QEvent.ActivationChange

A widget’s top-level window activation state has changed.

QEvent.ApplicationActivate

This enum has been deprecated. Use ApplicationStateChange instead.

QEvent.ApplicationActivated

This enum has been deprecated. Use ApplicationStateChange instead.

QEvent.ApplicationDeactivate

This enum has been deprecated. Use ApplicationStateChange instead.

QEvent.ApplicationFontChange

The default application font has changed.

QEvent.ApplicationLayoutDirectionChange

The default application layout direction has changed.

QEvent.ApplicationPaletteChange

The default application palette has changed.

QEvent.ApplicationStateChange

The state of the application has changed.

QEvent.ApplicationWindowIconChange

The application’s icon has changed.

QEvent.ChildAdded

An object gets a child ( QChildEvent ).

QEvent.ChildPolished

A widget child gets polished ( QChildEvent ).

QEvent.ChildRemoved

An object loses a child ( QChildEvent ).

QEvent.ChildWindowAdded

A child window was added to the window.

QEvent.ChildWindowRemoved

A child window was removed from the window.

QEvent.Clipboard

The clipboard contents have changed.

QEvent.Close

Widget was closed (QCloseEvent).

QEvent.CloseSoftwareInputPanel

A widget wants to close the software input panel (SIP).

QEvent.ContentsRectChange

The margins of the widget’s content rect changed.

QEvent.ContextMenu

Context popup menu (QContextMenuEvent).

QEvent.CursorChange

The widget’s cursor has changed.

QEvent.DeferredDelete

The object will be deleted after it has cleaned up (QDeferredDeleteEvent)

QEvent.DevicePixelRatioChange

The devicePixelRatio has changed for this widget’s or window’s underlying backing store.

QEvent.DragEnter

The cursor enters a widget during a drag and drop operation (QDragEnterEvent).

QEvent.DragLeave

The cursor leaves a widget during a drag and drop operation (QDragLeaveEvent).

QEvent.DragMove

A drag and drop operation is in progress (QDragMoveEvent).

QEvent.Drop

A drag and drop operation is completed (QDropEvent).

QEvent.DynamicPropertyChange

A dynamic property was added, changed, or removed from the object.

QEvent.EnabledChange

Widget’s enabled state has changed.

QEvent.Enter

Mouse enters widget’s boundaries (QEnterEvent).

QEvent.EnterEditFocus

An editor widget gains focus for editing. QT_KEYPAD_NAVIGATION must be defined.

QEvent.EnterWhatsThisMode

Send to toplevel widgets when the application enters “What’s This?” mode.

QEvent.Expose

Sent to a window when its on-screen contents are invalidated and need to be flushed from the backing store.

QEvent.FileOpen

File open request (QFileOpenEvent).

QEvent.FocusIn

Widget or Window gains keyboard focus (QFocusEvent).

QEvent.FocusOut

Widget or Window loses keyboard focus (QFocusEvent).

QEvent.FocusAboutToChange

Widget or Window focus is about to change (QFocusEvent)

QEvent.FontChange

Widget’s font has changed.

QEvent.Gesture

A gesture was triggered (QGestureEvent).

QEvent.GestureOverride

A gesture override was triggered (QGestureEvent).

QEvent.GrabKeyboard

Item gains keyboard grab (QGraphicsItem only).

QEvent.GrabMouse

Item gains mouse grab (QGraphicsItem only).

QEvent.GraphicsSceneContextMenu

Context popup menu over a graphics scene (QGraphicsSceneContextMenuEvent).

QEvent.GraphicsSceneDragEnter

The cursor enters a graphics scene during a drag and drop operation (QGraphicsSceneDragDropEvent).

QEvent.GraphicsSceneDragLeave

The cursor leaves a graphics scene during a drag and drop operation (QGraphicsSceneDragDropEvent).

QEvent.GraphicsSceneDragMove

A drag and drop operation is in progress over a scene (QGraphicsSceneDragDropEvent).

QEvent.GraphicsSceneDrop

A drag and drop operation is completed over a scene (QGraphicsSceneDragDropEvent).

QEvent.GraphicsSceneHelp

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

The mouse cursor leaves a hover item in a graphics scene (QGraphicsSceneHoverEvent).

QEvent.GraphicsSceneHoverMove

The mouse cursor moves inside a hover item in a graphics scene (QGraphicsSceneHoverEvent).

QEvent.GraphicsSceneMouseDoubleClick

Mouse press again (double click) in a graphics scene (QGraphicsSceneMouseEvent).

QEvent.GraphicsSceneMouseMove

Move mouse in a graphics scene (QGraphicsSceneMouseEvent).

QEvent.GraphicsSceneMousePress

Mouse press in a graphics scene (QGraphicsSceneMouseEvent).

QEvent.GraphicsSceneMouseRelease

Mouse release in a graphics scene (QGraphicsSceneMouseEvent).

QEvent.GraphicsSceneMove

Widget was moved (QGraphicsSceneMoveEvent).

QEvent.GraphicsSceneResize

Widget was resized (QGraphicsSceneResizeEvent).

QEvent.GraphicsSceneWheel

Mouse wheel rolled in a graphics scene (QGraphicsSceneWheelEvent).

QEvent.GraphicsSceneLeave

The cursor leaves a graphics scene (QGraphicsSceneWheelEvent).

QEvent.Hide

Widget was hidden (QHideEvent).

QEvent.HideToParent

A child widget has been hidden.

QEvent.HoverEnter

The mouse cursor enters a hover widget (QHoverEvent).

QEvent.HoverLeave

The mouse cursor leaves a hover widget (QHoverEvent).

QEvent.HoverMove

The mouse cursor moves inside a hover widget (QHoverEvent).

QEvent.IconDrag

The main icon of a window has been dragged away (QIconDragEvent).

QEvent.IconTextChange

Widget’s icon text has been changed. (Deprecated)

QEvent.InputMethod

An input method is being used (QInputMethodEvent).

QEvent.InputMethodQuery

A input method query event (QInputMethodQueryEvent)

QEvent.KeyboardLayoutChange

The keyboard layout has changed.

QEvent.KeyPress

Key press (QKeyEvent).

QEvent.KeyRelease

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

An editor widget loses focus for editing. QT_KEYPAD_NAVIGATION must be defined.

QEvent.LeaveWhatsThisMode

Send to toplevel widgets when the application leaves “What’s This?” mode.

QEvent.LocaleChange

The system locale has changed.

QEvent.NonClientAreaMouseButtonDblClick

A mouse double click occurred outside the client area (QMouseEvent).

QEvent.NonClientAreaMouseButtonPress

A mouse button press occurred outside the client area (QMouseEvent).

QEvent.NonClientAreaMouseButtonRelease

A mouse button release occurred outside the client area (QMouseEvent).

QEvent.NonClientAreaMouseMove

A mouse move occurred outside the client area (QMouseEvent).

QEvent.MacSizeChange

The user changed his widget sizes (macOS only).

QEvent.MetaCall

An asynchronous method invocation via invokeMethod() .

QEvent.ModifiedChange

Widgets modification state has been changed.

QEvent.MouseButtonDblClick

Mouse press again (QMouseEvent).

QEvent.MouseButtonPress

Mouse press (QMouseEvent).

QEvent.MouseButtonRelease

Mouse release (QMouseEvent).

QEvent.MouseMove

Mouse move (QMouseEvent).

QEvent.MouseTrackingChange

The mouse tracking state has changed.

QEvent.Move

Widget’s position changed (QMoveEvent).

QEvent.NativeGesture

The system has detected a gesture (QNativeGestureEvent).

QEvent.OrientationChange

The screens orientation has changes (QScreenOrientationChangeEvent).

QEvent.Paint

Screen update necessary (QPaintEvent).

QEvent.PaletteChange

Palette of the widget changed.

QEvent.ParentAboutToChange

The object parent is about to change. Only sent to some object types, such as QWidget.

QEvent.ParentChange

The object parent has changed. Only sent to some object types, such as QWidget.

QEvent.ParentWindowAboutToChange

The parent window is about to change.

QEvent.ParentWindowChange

The parent window has changed.

QEvent.PlatformPanel

A platform specific panel has been requested.

QEvent.PlatformSurface

A native platform surface has been created or is about to be destroyed (QPlatformSurfaceEvent).

QEvent.Polish

The widget is polished.

QEvent.PolishRequest

The widget should be polished.

QEvent.QueryWhatsThis

The widget should accept the event if it has “What’s This?” help (QHelpEvent).

QEvent.Quit

The application has exited.

QEvent.ReadOnlyChange

Widget’s read-only state has changed.

QEvent.RequestSoftwareInputPanel

A widget wants to open a software input panel (SIP).

QEvent.Resize

Widget’s size changed (QResizeEvent).

QEvent.ScrollPrepare

The object needs to fill in its geometry information (QScrollPrepareEvent).

QEvent.Scroll

The object needs to scroll to the supplied position (QScrollEvent).

QEvent.Shortcut

Key press in child for shortcut key handling (QShortcutEvent).

QEvent.ShortcutOverride

Key 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.Show

Widget was shown on screen (QShowEvent).

QEvent.ShowToParent

A child widget has been shown.

QEvent.SockAct

Socket activated, used to implement QSocketNotifier .

QEvent.StateMachineSignal

A signal delivered to a state machine (QStateMachine::SignalEvent).

QEvent.StateMachineWrapped

The event is a wrapper for, i.e., contains, another event (QStateMachine::WrappedEvent).

QEvent.StatusTip

A status tip is requested (QStatusTipEvent).

QEvent.StyleChange

Widget’s style has been changed.

QEvent.TabletMove

Wacom tablet move (QTabletEvent).

QEvent.TabletPress

Wacom tablet press (QTabletEvent).

QEvent.TabletRelease

Wacom tablet release (QTabletEvent).

QEvent.TabletEnterProximity

Wacom tablet enter proximity event (QTabletEvent), sent to QApplication.

QEvent.TabletLeaveProximity

Wacom tablet leave proximity event (QTabletEvent), sent to QApplication.

QEvent.TabletTrackingChange

The Wacom tablet tracking state has changed.

QEvent.ThreadChange

The object is moved to another thread. This is the last event sent to this object in the previous thread. See moveToThread() .

QEvent.Timer

Regular timer events ( QTimerEvent ).

QEvent.ToolBarChange

The toolbar button is toggled on macOS.

QEvent.ToolTip

A tooltip was requested (QHelpEvent).

QEvent.ToolTipChange

The widget’s tooltip has changed.

QEvent.TouchBegin

Beginning of a sequence of touch-screen or track-pad events (QTouchEvent).

QEvent.TouchCancel

Cancellation of touch-event sequence (QTouchEvent).

QEvent.TouchEnd

End of touch-event sequence (QTouchEvent).

QEvent.TouchUpdate

Touch-screen event (QTouchEvent).

QEvent.UngrabKeyboard

Item loses keyboard grab (QGraphicsItem only).

QEvent.UngrabMouse

Item loses mouse grab (QGraphicsItem, QQuickItem).

QEvent.UpdateLater

The widget should be queued to be repainted at a later time.

QEvent.UpdateRequest

The widget should be repainted.

QEvent.WhatsThis

The widget should reveal “What’s This?” help (QHelpEvent).

QEvent.WhatsThisClicked

A link in a widget’s “What’s This?” help was clicked.

QEvent.Wheel

Mouse wheel rolled (QWheelEvent).

QEvent.WinEventAct

A Windows-specific activation event has occurred.

QEvent.WindowActivate

Window was activated.

QEvent.WindowBlocked

The window is blocked by a modal dialog.

QEvent.WindowDeactivate

Window was deactivated.

QEvent.WindowIconChange

The window’s icon has changed.

QEvent.WindowStateChange

The window’s state (minimized, maximized or full-screen) has changed (QWindowStateChangeEvent).

QEvent.WindowTitleChange

The window title has changed.

QEvent.WindowUnblocked

The window is unblocked after a modal dialog exited.

QEvent.WinIdChange

The window system identifier for this native widget has changed.

QEvent.ZOrderChange

The widget’s z-order has changed. This event is never sent to top level windows.

User events should have values between User and MaxUser:

Constant

Description

QEvent.User

User-defined event.

QEvent.MaxUser

Last 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.

__init__(type)#
Parameters:

typeType

Constructs an event object of type type.

__init__(arg__1)
Parameters:

arg__1QEvent

Constructs an event object of type type.

__repr__()#
Return type:

object

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()

clone()#
Return type:

QEvent

Creates and returns an identical copy of this event.

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()

isAccepted()#
Return type:

bool

isInputEvent()#
Return type:

bool

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

isPointerEvent()#
Return type:

bool

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

isSinglePointEvent()#
Return type:

bool

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

static registerEventType([hint=-1])#
Parameters:

hint – int

Return type:

int

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

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

setAccepted(accepted)#
Parameters:

accepted – bool

See also

isAccepted()

spontaneous()#
Return type:

bool

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

type()#
Return type:

Type

Returns the event type.