From 2137f41ca0df3c83abce9dd386074e0fd09a33dc Mon Sep 17 00:00:00 2001 From: Bjoern Erik Nilsen Date: Tue, 5 May 2009 15:33:42 +0200 Subject: Partially revert 37c72476fc444d3089075473cb4e9aa42ed64694 The problem was that mouse move events were not forwarded to the scene when mouse tracking was explicitly enabled on the view. Mouse tracking is disabled by default unless the scene contains an item that accepts hover events or has a cursor set. A mouse move event can only occur if: 1) a mouse button is pressed while moving the mouse 2) mouse tracking is enabled That means the part I've reverted was only hitting when mouse tracking was explicitly enabled, which is wrong. We always have to forward mouse move events to the scene if the view is getting them in the first place. Auto test included. Reviewed-by: Andreas --- src/gui/graphicsview/qgraphicsview.cpp | 4 ---- tests/auto/qgraphicsview/tst_qgraphicsview.cpp | 27 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp index 7720a10..644e843 100644 --- a/src/gui/graphicsview/qgraphicsview.cpp +++ b/src/gui/graphicsview/qgraphicsview.cpp @@ -587,10 +587,6 @@ void QGraphicsViewPrivate::mouseMoveEventHandler(QMouseEvent *event) return; if (!scene) return; - if (scene->d_func()->allItemsIgnoreHoverEvents && scene->d_func()->allItemsUseDefaultCursor - && !event->buttons()) { // forward event to the scene if something is pressed. - return; // No need to process this event further. - } QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseMove); mouseEvent.setWidget(q->viewport()); diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp index ca88afc..bb61f90 100644 --- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp @@ -190,6 +190,7 @@ private slots: void scrollAfterResize(); void centerOnDirtyItem(); void mouseTracking(); + void mouseTracking2(); // task specific tests below me void task172231_untransformableItems(); @@ -3173,5 +3174,31 @@ void tst_QGraphicsView::mouseTracking() } } +void tst_QGraphicsView::mouseTracking2() +{ + // Make sure mouse move events propagates to the scene when + // mouse tracking is explicitly enabled on the view, + // even when all items ignore hover events / use default cursor. + + QGraphicsScene scene; + scene.addRect(0, 0, 100, 100); + + QGraphicsView view(&scene); + view.show(); +#ifdef Q_WS_X11 + qt_x11_wait_for_window_manager(&view); +#endif + QTest::qWait(200); + + QVERIFY(!view.viewport()->hasMouseTracking()); + view.viewport()->setMouseTracking(true); // Explicitly enable mouse tracking. + QVERIFY(view.viewport()->hasMouseTracking()); + + EventSpy spy(&scene, QEvent::GraphicsSceneMouseMove); + QCOMPARE(spy.count(), 0); + sendMouseMove(view.viewport(), view.viewport()->rect().center()); + QCOMPARE(spy.count(), 1); +} + QTEST_MAIN(tst_QGraphicsView) #include "tst_qgraphicsview.moc" -- cgit v0.12