Show widget cursor after restoring last override cursor
authorMiikka Heikkinen <miikka.heikkinen@digia.com>
Wed, 3 Oct 2012 09:06:14 +0000 (12:06 +0300)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Thu, 4 Oct 2012 07:13:33 +0000 (09:13 +0200)
qwidget_qpa.cpp was setting cursor directly to platform window, so
QWindow didn't actually know what cursor was supposed to be shown.

Since QWindow now supports setting cursor and has override cursor
handling there, set cursor via QWindow instead of platform window.
Also changed QGuiApplication override cursor handling so that
it will query the cursor from QWindow if there is no override cursor.
With these changes, widget's custom cursor will be properly shown
when final override cursor is restored.

Task-number: QTBUG-24674
Change-Id: I2d2bb1027779256f9d6de560b6533f45e205ffe9
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
src/gui/kernel/qguiapplication.cpp
src/widgets/kernel/qwidget_qpa.cpp

index 7e7997d..84f22de 100644 (file)
@@ -2328,6 +2328,15 @@ static inline void applyCursor(const QList<QWindow *> &l, const QCursor &c)
     }
 }
 
+static inline void applyWindowCursor(const QList<QWindow *> &l)
+{
+    for (int i = 0; i < l.size(); ++i) {
+        QWindow *w = l.at(i);
+        if (w->handle() && w->windowType() != Qt::Desktop)
+            applyCursor(w, w->cursor());
+    }
+}
+
 /*!
     \fn void QGuiApplication::setOverrideCursor(const QCursor &cursor)
 
@@ -2376,8 +2385,12 @@ void QGuiApplication::restoreOverrideCursor()
     if (qGuiApp->d_func()->cursor_list.isEmpty())
         return;
     qGuiApp->d_func()->cursor_list.removeFirst();
-    QCursor c(qGuiApp->d_func()->cursor_list.value(0, QCursor()));
-    applyCursor(QGuiApplicationPrivate::window_list, c);
+    if (qGuiApp->d_func()->cursor_list.size() > 0) {
+        QCursor c(qGuiApp->d_func()->cursor_list.value(0));
+        applyCursor(QGuiApplicationPrivate::window_list, c);
+    } else {
+        applyWindowCursor(QGuiApplicationPrivate::window_list);
+    }
 }
 #endif// QT_NO_CURSOR
 
index c6680ea..86d8da2 100644 (file)
@@ -1064,9 +1064,7 @@ void QWidgetPrivate::setModal_sys()
 static inline void applyCursor(QWidget *w, QCursor c)
 {
     if (QWindow *window = w->windowHandle())
-        if (const QScreen *screen = window->screen())
-            if (QPlatformCursor *cursor = screen->handle()->cursor())
-                cursor->changeCursor(&c, window);
+        window->setCursor(c);
 }
 
 void qt_qpa_set_cursor(QWidget *w, bool force)
@@ -1097,10 +1095,7 @@ void qt_qpa_set_cursor(QWidget *w, bool force)
         return;
 
     if (w->isWindow() || w->testAttribute(Qt::WA_SetCursor)) {
-        QCursor *oc = QApplication::overrideCursor();
-        if (oc)
-            applyCursor(nativeParent, *oc);
-        else if (w->isEnabled())
+        if (w->isEnabled())
             applyCursor(nativeParent, w->cursor());
         else
             // Enforce the windows behavior of clearing the cursor on