Handle return of GetCursorPos window api function
GetCursorPos api function can return false in some cases. In those cases no cursor position is returned, so we ignore it and instead return the last cached position. Fixes: QTBUG-44692 Change-Id: Ie961fe166ef9f1580bd504a55ddfe431e56b3aed Reviewed-by: Wladimir Leuschner <wladimir.leuschner@qt.io> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
This commit is contained in:
parent
b429da48be
commit
e9662a4b66
@ -523,6 +523,7 @@ CursorHandlePtr QWindowsCursor::standardWindowCursor(Qt::CursorShape shape)
|
||||
|
||||
HCURSOR QWindowsCursor::m_overriddenCursor = nullptr;
|
||||
HCURSOR QWindowsCursor::m_overrideCursor = nullptr;
|
||||
POINT QWindowsCursor::m_cursorPositionCache = {0,0};
|
||||
|
||||
/*!
|
||||
\brief Return cached pixmap cursor or create new one.
|
||||
@ -633,8 +634,9 @@ void QWindowsCursor::clearOverrideCursor()
|
||||
QPoint QWindowsCursor::mousePosition()
|
||||
{
|
||||
POINT p;
|
||||
GetCursorPos(&p);
|
||||
return QPoint(p.x, p.y);
|
||||
if (GetCursorPos(&p))
|
||||
m_cursorPositionCache = p;
|
||||
return QPoint(m_cursorPositionCache.x, m_cursorPositionCache.y);
|
||||
}
|
||||
|
||||
QWindowsCursor::State QWindowsCursor::cursorState()
|
||||
@ -658,6 +660,7 @@ QPoint QWindowsCursor::pos() const
|
||||
|
||||
void QWindowsCursor::setPos(const QPoint &pos)
|
||||
{
|
||||
m_cursorPositionCache = {pos.x(), pos.y()};
|
||||
SetCursorPos(pos.x() , pos.y());
|
||||
}
|
||||
|
||||
|
@ -111,6 +111,7 @@ private:
|
||||
|
||||
static HCURSOR m_overriddenCursor;
|
||||
static HCURSOR m_overrideCursor;
|
||||
static POINT m_cursorPositionCache;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
Loading…
x
Reference in New Issue
Block a user