QHoverEvent Class▲
-
Header: QHoverEvent
-
CMake:
find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
-
qmake: QT += gui
-
Inherits: QSinglePointEvent
-
Group: QHoverEvent is part of events
Detailed Description▲
Mouse events occur when a mouse cursor is moved into, out of, or within a widget, and if the widget has the Qt::WA_Hover attribute.
The function pos() gives the current cursor position, while oldPos() gives the old mouse position.
There are a few similarities between the events QEvent::HoverEnter and QEvent::HoverLeave, and the events QEvent::Enter and QEvent::Leave. However, they are slightly different because we do an update() in the event handler of HoverEnter and HoverLeave.
QEvent::HoverMove is also slightly different from QEvent::MouseMove. Let us consider a top-level window A containing a child B which in turn contains a child C (all with mouse tracking enabled):
Now, if you move the cursor from the top to the bottom in the middle of A, you will get the following QEvent::MouseMove events:
-
A::MouseMove
-
B::MouseMove
-
C::MouseMove
You will get the same events for QEvent::HoverMove, except that the event always propagates to the top-level regardless whether the event is accepted or not. It will only stop propagating with the Qt::WA_NoMousePropagation attribute.
In this case the events will occur in the following way:
-
A::HoverMove
-
A::HoverMove, B::HoverMove
-
A::HoverMove, B::HoverMove, C::HoverMove
Member Function Documentation▲
QHoverEvent::QHoverEvent(QEvent::Type type, const QPointF &scenePos, const QPointF &globalPos, const QPointF &oldPos, Qt::KeyboardModifiers modifiers = Qt::NoModifier, const QPointingDevice *device = QPointingDevice::primaryPointingDevice())▲
Constructs a hover event object originating from device.
The type parameter must be QEvent::HoverEnter, QEvent::HoverLeave, or QEvent::HoverMove.
The scenePos is the current mouse cursor's position relative to the receiving window or scene, oldPos is its previous such position, and globalPos is the mouse position in absolute coordinates. modifiers hold the state of all keyboard modifiers at the time of the event.
QPoint QHoverEvent::oldPos() const▲
Returns the previous position of the mouse cursor, relative to the widget that received the event. If there is no previous position, oldPos() will return the same position as pos().
On QEvent::HoverEnter events, this position will always be QPoint(-1, -1).
See Also▲
See also pos()
QPointF QHoverEvent::oldPosF() const▲
Returns the previous position of the mouse cursor, relative to the widget that received the event. If there is no previous position, oldPosF() will return the same position as posF().
On QEvent::HoverEnter events, this position will always be QPointF(-1, -1).
See Also▲
See also posF()
Obsolete Members for QHoverEvent▲
The following members of class QHoverEvent are deprecated. We strongly advise against using them in new code.
Obsolete Member Function Documentation▲
QHoverEvent::QHoverEvent(QEvent::Type type, const QPointF &pos, const QPointF &oldPos, Qt::KeyboardModifiers modifiers = Qt::NoModifier, const QPointingDevice *device = QPointingDevice::primaryPointingDevice())▲
This function is deprecated since 6.3. We strongly advise against using it in new code.
Use the other constructor instead (global position is required).
Constructs a hover event object originating from device.
The type parameter must be QEvent::HoverEnter, QEvent::HoverLeave, or QEvent::HoverMove.
The pos is the current mouse cursor's position relative to the receiving widget, while oldPos is its previous such position. modifiers hold the state of all keyboard modifiers at the time of the event.
QPoint QHoverEvent::pos() const▲
This function is deprecated since 6.0. We strongly advise against using it in new code.
Use position().toPoint() instead.
Returns the position of the mouse cursor, relative to the widget that received the event.
On QEvent::HoverLeave events, this position will always be QPoint(-1, -1).
See Also▲
See also oldPos()
QPointF QHoverEvent::posF() const▲
This function is deprecated since 6.0. We strongly advise against using it in new code.
Use position() instead.
Returns the position of the mouse cursor, relative to the widget that received the event.
On QEvent::HoverLeave events, this position will always be QPointF(-1, -1).
See Also▲
See also oldPosF()