From 37d25a5112cdf13620715c03d6bdbd1bc3cde515 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Wed, 2 Dec 2015 09:51:35 +0100 Subject: QQuickWidget: pass enter and leave events to the offscreen window By passing the enter and leave events to the offscreen window it will enable mouse areas inside a QQuickWidget to know when the mouse has actually entered or left the area if it is covering the whole item. Task-number: QTBUG-45557 Change-Id: I670ebe30e367e919c73fed449bf2bed7ca42b5fd Reviewed-by: Gatis Paeglis --- .../quickwidgets/qquickwidget/data/enterleave.qml | 12 +++++++++++ .../quickwidgets/qquickwidget/tst_qquickwidget.cpp | 25 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 tests/auto/quickwidgets/qquickwidget/data/enterleave.qml (limited to 'tests') diff --git a/tests/auto/quickwidgets/qquickwidget/data/enterleave.qml b/tests/auto/quickwidgets/qquickwidget/data/enterleave.qml new file mode 100644 index 0000000000..b3057e30ad --- /dev/null +++ b/tests/auto/quickwidgets/qquickwidget/data/enterleave.qml @@ -0,0 +1,12 @@ +import QtQuick 2.0 + +Rectangle { + property bool hasMouse: mouseArea.containsMouse + height: 200 + width: 200 + MouseArea { + id: mouseArea + hoverEnabled: true + anchors.fill: parent + } +} diff --git a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp index ee49c9c7ad..e4991a5f26 100644 --- a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp +++ b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp @@ -61,6 +61,7 @@ private slots: void nullEngine(); void keyEvents(); void shortcuts(); + void enterLeave(); }; @@ -408,6 +409,30 @@ void tst_qquickwidget::shortcuts() QTRY_VERIFY(filter.shortcutOk); } +void tst_qquickwidget::enterLeave() +{ + QQuickWidget view; + view.setSource(testFileUrl("enterleave.qml")); + + // Ensure it is not inside the window first + QCursor::setPos(QPoint(50, 50)); + QTRY_VERIFY(QCursor::pos() == QPoint(50, 50)); + + view.move(100, 100); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view, 5000)); + QQuickItem *rootItem = view.rootObject(); + QVERIFY(rootItem); + + QTRY_VERIFY(!rootItem->property("hasMouse").toBool()); + // Check the enter + QCursor::setPos(view.pos() + QPoint(50, 50)); + QTRY_VERIFY(rootItem->property("hasMouse").toBool()); + // Now check the leave + QCursor::setPos(view.pos() - QPoint(50, 50)); + QTRY_VERIFY(!rootItem->property("hasMouse").toBool()); +} + QTEST_MAIN(tst_qquickwidget) #include "tst_qquickwidget.moc" -- cgit v1.2.3