QHoverEvent 类

QHoverEvent class contains parameters that describe a mouse event. 更多...

头: #include <QHoverEvent>
qmake: QT += gui
继承: QInputEvent

公共函数

QHoverEvent (Type type , const QPointF & pos , const QPointF & oldPos , Qt::KeyboardModifiers modifiers = Qt::NoModifier)
QPoint oldPos () const
const QPointF & oldPosF () const
QPoint pos () const
const QPointF & posF () const

额外继承成员

详细描述

QHoverEvent class contains parameters that describe a mouse event.

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 属性。

函数 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:

  1. A::MouseMove
  2. B::MouseMove
  3. 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 属性。

In this case the events will occur in the following way:

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

成员函数文档编制

QHoverEvent:: QHoverEvent ( Type type , const QPointF & pos , const QPointF & oldPos , Qt::KeyboardModifiers modifiers = Qt::NoModifier)

Constructs a hover event object.

type 参数必须是 QEvent::HoverEnter , QEvent::HoverLeave ,或 QEvent::HoverMove .

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:: 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).

另请参阅 pos ().

const 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).

另请参阅 posF ().

QPoint QHoverEvent:: pos () const

返回鼠标光标的位置,相对于接收事件的 Widget。

On QEvent::HoverLeave events, this position will always be QPoint (-1, -1).

另请参阅 oldPos ().

const QPointF &QHoverEvent:: posF () const

返回鼠标光标的位置,相对于接收事件的 Widget。

On QEvent::HoverLeave events, this position will always be QPointF (-1, -1).

另请参阅 oldPosF ().