diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2022-01-31 16:09:38 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2022-02-03 10:18:43 +0100 |
commit | 0a64a044b6c1c44b0a2bb2be5e70fda920f5f6bf (patch) | |
tree | cf52d91141e3745f3aa3e550948de4256ce2a85e /src/gui/kernel/qevent.cpp | |
parent | 5c6f8b2c67852dbd3674658736d1a1ab96a2571d (diff) |
Add a QHoverEvent ctor taking global mouse position; deprecate the other
The QSinglePointEvent ctor assumes that the given globalPos is correct,
so it was wrong that the QHoverEvent ctor passed along a local position
as global. It's better to require globalPos as an argument; and in fact
it seems that everywhere we construct a QHoverEvent, global position is
available, or possible to get by transformation (which is better than
resorting to QCursor::pos()).
Also, don't convert to QPoint: pointer events have qreal resolution and
there's no reason to truncate them.
Fixes: QTBUG-100324
Change-Id: I919455da36265988d3d149eb97563c9ed0d2c660
Pick-to: 6.3
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/gui/kernel/qevent.cpp')
-rw-r--r-- | src/gui/kernel/qevent.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 5e7c2a574c..ec2711b582 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -1069,6 +1069,27 @@ Qt::MouseEventFlags QMouseEvent::flags() const QEvent::HoverLeave, or QEvent::HoverMove. The \a pos is the current mouse cursor's position relative to the + receiving widget, \a oldPos is its previous such position, and + \a globalPos is the mouse position in absolute coordinates. + \a modifiers hold the state of all keyboard modifiers at the time + of the event. +*/ +QHoverEvent::QHoverEvent(Type type, const QPointF &pos, const QPointF &globalPos, const QPointF &oldPos, + Qt::KeyboardModifiers modifiers, const QPointingDevice *device) + : QSinglePointEvent(type, device, pos, pos, globalPos, Qt::NoButton, Qt::NoButton, modifiers), m_oldPos(oldPos) +{ +} + +#if QT_DEPRECATED_SINCE(6, 3) +/*! + \deprecated [6.3] Use the other constructor instead (global position is required). + + Constructs a hover event object originating from \a device. + + The \a type parameter must be QEvent::HoverEnter, + QEvent::HoverLeave, or QEvent::HoverMove. + + The \a pos is the current mouse cursor's position relative to the receiving widget, while \a oldPos is its previous such position. \a modifiers hold the state of all keyboard modifiers at the time of the event. @@ -1078,6 +1099,7 @@ QHoverEvent::QHoverEvent(Type type, const QPointF &pos, const QPointF &oldPos, : QSinglePointEvent(type, device, pos, pos, pos, Qt::NoButton, Qt::NoButton, modifiers), m_oldPos(oldPos) { } +#endif /*! \internal |