QHoverEvent 类

QHoverEvent 类包含鼠标事件的描述参数。 更多...

头: #include <QHoverEvent>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui
继承: QSinglePointEvent

公共函数

QHoverEvent (QEvent::Type type , const QPointF & scenePos , const QPointF & globalPos , const QPointF & oldPos , Qt::KeyboardModifiers modifiers = Qt::NoModifier, const QPointingDevice * device = QPointingDevice::primaryPointingDevice())
QPoint oldPos () const
QPointF oldPosF () const

详细描述

出现鼠标事件,当鼠标光标移入/移出 Widget,或在 Widget 内移动时,且若小部件拥有 Qt::WA_Hover 属性。

The function pos() gives the current cursor position, while oldPos () 给出旧鼠标位置。

有一些相似介于事件 QEvent::HoverEnter and QEvent::HoverLeave ,和事件 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 也稍微不同于 QEvent::MouseMove 。让我们考虑顶层 A 窗口,其包含子级 B,而 B 又包含子级 C (都有启用鼠标跟踪):

现在,若将光标从 A 中间的顶部移到底部,将获得下列 QEvent::MouseMove 事件:

  1. A::MouseMove
  2. B::MouseMove
  3. C::MouseMove

将获得相同事件 QEvent::HoverMove ,除事件始终会被传播给顶层外,不管事件是否被接受。它才会停止传播采用 Qt::WA_NoMousePropagation 属性。

在此情况下,事件将按下列方式出现:

  1. A::HoverMove
  2. A::HoverMove, B::HoverMove
  3. A::HoverMove, B::HoverMove, C::HoverMove

成员函数文档编制

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 参数必须是 QEvent::HoverEnter , QEvent::HoverLeave ,或 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 是按绝对坐标的鼠标位置。 modifiers 保持事件发生时所有键盘修饰符的状态。

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 事件,此位置将始终是 QPoint (-1, -1).

另请参阅 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 事件,此位置将始终是 QPointF (-1, -1).

另请参阅 posF ().