Windows QPA: Fix override cursor being cleared when crossing window borders

Override cursors can be modified externally when for example crossing
window borders. Add helper function to enforce the cursor again to
QWindowsWindow::applyCursor() which is called for enter events.

Task-number: QTBUG-69637
Change-Id: Ibea4da9f2aac81377002b626daae64b1102f6c2b
Reviewed-by: Andre de la Rocha <andre.rocha@qt.io>
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
This commit is contained in:
Friedemann Kleint 2018-07-30 09:09:03 +02:00
parent e386cd03d1
commit 46fc3d3729
3 changed files with 20 additions and 5 deletions

View File

@ -549,6 +549,7 @@ CursorHandlePtr QWindowsCursor::standardWindowCursor(Qt::CursorShape shape)
} }
HCURSOR QWindowsCursor::m_overriddenCursor = nullptr; HCURSOR QWindowsCursor::m_overriddenCursor = nullptr;
HCURSOR QWindowsCursor::m_overrideCursor = nullptr;
/*! /*!
\brief Return cached pixmap cursor or create new one. \brief Return cached pixmap cursor or create new one.
@ -621,11 +622,20 @@ void QWindowsCursor::changeCursor(QCursor *cursorIn, QWindow *window)
} }
} }
// QTBUG-69637: Override cursors can get reset externally when moving across
// window borders. Enforce the cursor again (to be called from enter event).
void QWindowsCursor::enforceOverrideCursor()
{
if (hasOverrideCursor() && m_overrideCursor != GetCursor())
SetCursor(m_overrideCursor);
}
void QWindowsCursor::setOverrideCursor(const QCursor &cursor) void QWindowsCursor::setOverrideCursor(const QCursor &cursor)
{ {
const CursorHandlePtr wcursor = cursorHandle(cursor); const CursorHandlePtr wcursor = cursorHandle(cursor);
if (wcursor->handle()) { if (const auto overrideCursor = wcursor->handle()) {
const HCURSOR previousCursor = SetCursor(wcursor->handle()); m_overrideCursor = overrideCursor;
const HCURSOR previousCursor = SetCursor(overrideCursor);
if (m_overriddenCursor == nullptr) if (m_overriddenCursor == nullptr)
m_overriddenCursor = previousCursor; m_overriddenCursor = previousCursor;
} else { } else {
@ -638,7 +648,7 @@ void QWindowsCursor::clearOverrideCursor()
{ {
if (m_overriddenCursor) { if (m_overriddenCursor) {
SetCursor(m_overriddenCursor); SetCursor(m_overriddenCursor);
m_overriddenCursor = nullptr; m_overriddenCursor = m_overrideCursor = nullptr;
} }
} }

View File

@ -107,7 +107,8 @@ public:
void changeCursor(QCursor * widgetCursor, QWindow * widget) override; void changeCursor(QCursor * widgetCursor, QWindow * widget) override;
void setOverrideCursor(const QCursor &cursor) override; void setOverrideCursor(const QCursor &cursor) override;
void clearOverrideCursor() override; void clearOverrideCursor() override;
bool hasOverrideCursor() const { return m_overriddenCursor != nullptr; } static void enforceOverrideCursor();
static bool hasOverrideCursor() { return m_overriddenCursor != nullptr; }
QPoint pos() const override; QPoint pos() const override;
void setPos(const QPoint &pos) override; void setPos(const QPoint &pos) override;
@ -143,6 +144,7 @@ private:
mutable QPixmap m_ignoreDragCursor; mutable QPixmap m_ignoreDragCursor;
static HCURSOR m_overriddenCursor; static HCURSOR m_overriddenCursor;
static HCURSOR m_overrideCursor;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -2419,8 +2419,11 @@ static inline bool applyNewCursor(const QWindow *w)
void QWindowsWindow::applyCursor() void QWindowsWindow::applyCursor()
{ {
if (static_cast<const QWindowsCursor *>(screen()->cursor())->hasOverrideCursor()) if (QWindowsCursor::hasOverrideCursor()) {
if (isTopLevel())
QWindowsCursor::enforceOverrideCursor();
return; return;
}
#ifndef QT_NO_CURSOR #ifndef QT_NO_CURSOR
if (m_cursor->isNull()) { // Recurse up to parent with non-null cursor. Set default for toplevel. if (m_cursor->isNull()) { // Recurse up to parent with non-null cursor. Set default for toplevel.
if (const QWindow *p = window()->parent()) { if (const QWindow *p = window()->parent()) {