Unset the cursor when an Item is unparented
authorDaiwei Li <daiweili@suitabletech.com>
Fri, 9 Aug 2013 19:04:41 +0000 (12:04 -0700)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 14 Aug 2013 21:46:54 +0000 (23:46 +0200)
It's possible for a cursor to get stuck if an item
gets deleted. QQuickItemPrivate::derefWindow sets
the cursorItem in QQuickWindowPrivate to 0, but
doesn't unset the cursor. This causes the cursor
to get stuck until the user hovers their mouse over
an item that has a cursor set.

Change-Id: I1d5d3ff13d69c76e4f8fe86b1f5b669bb714ecca
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
src/quick/items/qquickitem.cpp
tests/auto/quick/qquickwindow/tst_qquickwindow.cpp

index 5863c52..547b795 100644 (file)
@@ -2565,8 +2565,10 @@ void QQuickItemPrivate::derefWindow()
     if (c->mouseGrabberItem == q)
         c->mouseGrabberItem = 0;
 #ifndef QT_NO_CURSOR
-    if (c->cursorItem == q)
+    if (c->cursorItem == q) {
         c->cursorItem = 0;
+        window->unsetCursor();
+    }
 #endif
     c->hoverItems.removeAll(q);
     if (itemNodeInstance)
index 4a61746..17999ed 100644 (file)
@@ -1294,23 +1294,23 @@ void tst_qquickwindow::cursor()
     QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(100, 100));
 
     // Remove the cursor item from the scene. Theoretically this should make parentItem the
-    // cursorItem, but given the situation will correct itself after the next mouse move it's
-    // probably better left as is to avoid unnecessary work during tear down.
+    // cursorItem, but given the situation will correct itself after the next mouse move it
+    // simply unsets the window cursor for now.
     childItem.setParentItem(0);
-    QCOMPARE(window.cursor().shape(), Qt::WaitCursor);
+    QCOMPARE(window.cursor().shape(), Qt::ArrowCursor);
 
     parentItem.setCursor(Qt::SizeAllCursor);
     QCOMPARE(parentItem.cursor().shape(), Qt::SizeAllCursor);
-    QCOMPARE(window.cursor().shape(), Qt::WaitCursor);
+    QCOMPARE(window.cursor().shape(), Qt::ArrowCursor);
 
     // Changing the cursor of an un-parented item doesn't affect the window's cursor.
     childItem.setCursor(Qt::ClosedHandCursor);
     QCOMPARE(childItem.cursor().shape(), Qt::ClosedHandCursor);
-    QCOMPARE(window.cursor().shape(), Qt::WaitCursor);
+    QCOMPARE(window.cursor().shape(), Qt::ArrowCursor);
 
     childItem.unsetCursor();
     QCOMPARE(childItem.cursor().shape(), Qt::ArrowCursor);
-    QCOMPARE(window.cursor().shape(), Qt::WaitCursor);
+    QCOMPARE(window.cursor().shape(), Qt::ArrowCursor);
 
     QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(100, 101));
     QCOMPARE(window.cursor().shape(), Qt::SizeAllCursor);