From c24a7377dd9cfb503b43ef3f5a2d5cac9a4e1b8c Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 14 Jan 2013 10:00:12 +0100 Subject: Regression: Fix setting of custom cursors for native widgets. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, there is no concept of not having a cursor set on a Window. Qt::ArrowCursor is always set instead. This causes bugs when native child widgets are involved, for example setting a cursor on the native widget's parent no longer works since the child's Qt::ArrowCursor applies. Introduce QWindowPrivate::hasCursor tracking whether a cursor has been explicitly set and clear in QWindow::unsetCursor(). Handle 0 in QPlatformCursor::changeCursor() to mean "unsetCursor()": - Windows: Introduce default constructor for QWindowsWindowCursor meaning "0". Search for applicable parent cursor in applyCursor. - XCB: No big changes required, set XCB_CURSOR_NONE for no cursor. - Other platforms: Assume Qt::ArrowCursor when cursor = 0 is passed for now. Task-number: QTBUG-28879 Change-Id: Id82722592f3cd5fe577a5b64dcc600c85cfea484 Reviewed-by: Jonathan Liu Reviewed-by: Morten Johan Sørvig Reviewed-by: Samuel Rødal --- src/gui/kernel/qwindow.cpp | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) (limited to 'src/gui/kernel/qwindow.cpp') diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 22ad748fb5..b05d6c577e 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -284,7 +284,7 @@ void QWindow::setVisible(bool visible) } #ifndef QT_NO_CURSOR - if (visible) + if (visible && d->hasCursor) d->applyCursor(); #endif d->platformWindow->setVisible(visible); @@ -1947,13 +1947,7 @@ void QWindowPrivate::maybeQuitOnLastWindowClosed() void QWindow::setCursor(const QCursor &cursor) { Q_D(QWindow); - d->cursor = cursor; - // Only attempt to set cursor and emit signal if there is an actual platform cursor - if (d->screen->handle()->cursor()) { - d->applyCursor(); - QEvent event(QEvent::CursorChange); - QGuiApplication::sendEvent(this, &event); - } + d->setCursor(&cursor); } /*! @@ -1961,7 +1955,8 @@ void QWindow::setCursor(const QCursor &cursor) */ void QWindow::unsetCursor() { - setCursor(Qt::ArrowCursor); + Q_D(QWindow); + d->setCursor(0); } /*! @@ -1975,14 +1970,39 @@ QCursor QWindow::cursor() const return d->cursor; } +void QWindowPrivate::setCursor(const QCursor *newCursor) +{ + + Q_Q(QWindow); + if (newCursor) { + const Qt::CursorShape newShape = newCursor->shape(); + if (newShape <= Qt::LastCursor && hasCursor && newShape == cursor.shape()) + return; // Unchanged and no bitmap/custom cursor. + cursor = *newCursor; + hasCursor = true; + } else { + if (!hasCursor) + return; + cursor = QCursor(Qt::ArrowCursor); + hasCursor = false; + } + // Only attempt to set cursor and emit signal if there is an actual platform cursor + if (screen->handle()->cursor()) { + applyCursor(); + QEvent event(QEvent::CursorChange); + QGuiApplication::sendEvent(q, &event); + } +} + void QWindowPrivate::applyCursor() { Q_Q(QWindow); if (platformWindow) { if (QPlatformCursor *platformCursor = screen->handle()->cursor()) { - QCursor *oc = QGuiApplication::overrideCursor(); - QCursor c = oc ? *oc : cursor; - platformCursor->changeCursor(&c, q); + QCursor *c = QGuiApplication::overrideCursor(); + if (!c && hasCursor) + c = &cursor; + platformCursor->changeCursor(c, q); } } } -- cgit v1.2.3