diff options
Diffstat (limited to 'tests/auto/qgraphicsview')
-rw-r--r-- | tests/auto/qgraphicsview/tst_qgraphicsview.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp index dcd679f..cf697bb 100644 --- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp @@ -246,6 +246,7 @@ private slots: void QTBUG_4151_clipAndIgnore(); void QTBUG_5859_exposedRect(); void QTBUG_7438_cursor(); + void hoverLeave(); void QTBUG_16063_microFocusRect(); public slots: @@ -4451,6 +4452,60 @@ void tst_QGraphicsView::QTBUG_7438_cursor() #endif } +class GraphicsItemWithHover : public QGraphicsRectItem +{ +public: + GraphicsItemWithHover() + : receivedEnterEvent(false), receivedLeaveEvent(false), + enterWidget(0), leaveWidget(0) + { + setRect(0, 0, 100, 100); + setAcceptHoverEvents(true); + } + + bool sceneEvent(QEvent *event) + { + if (event->type() == QEvent::GraphicsSceneHoverEnter) { + receivedEnterEvent = true; + enterWidget = static_cast<QGraphicsSceneHoverEvent *>(event)->widget(); + } else if (event->type() == QEvent::GraphicsSceneHoverLeave) { + receivedLeaveEvent = true; + leaveWidget = static_cast<QGraphicsSceneHoverEvent *>(event)->widget(); + } + return QGraphicsRectItem::sceneEvent(event); + } + + bool receivedEnterEvent; + bool receivedLeaveEvent; + QWidget *enterWidget; + QWidget *leaveWidget; +}; + +void tst_QGraphicsView::hoverLeave() +{ + QGraphicsScene scene; + QGraphicsView view(&scene); + GraphicsItemWithHover *item = new GraphicsItemWithHover; + scene.addItem(item); + + // move the cursor out of the way + QCursor::setPos(1,1); + + view.show(); + QTest::qWaitForWindowShown(&view); + + QPoint pos = view.viewport()->mapToGlobal(view.mapFromScene(item->mapToScene(10, 10))); + QCursor::setPos(pos); + QTest::qWait(200); + QVERIFY(item->receivedEnterEvent); + QCOMPARE(item->enterWidget, view.viewport()); + + QCursor::setPos(0,0); + QTest::qWait(200); + QVERIFY(item->receivedLeaveEvent); + QCOMPARE(item->leaveWidget, view.viewport()); +} + class IMItem : public QGraphicsRectItem { public: |