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 (都有啓用鼠標追蹤):

Screenshot showing widgets A, B, C stacked on top of each other

現在,若將光標從 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 ().

內容

  1. 公共函數

  2. 詳細描述