diff options
author | Dan Cape <dcape@qnx.com> | 2015-10-07 15:46:14 -0400 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2016-07-21 14:42:39 +0000 |
commit | 0a87552e8122cdda58160da2dd549da411d9093c (patch) | |
tree | 659149c08681eb12e7f40ba651d499c50fccadb4 /tests/auto/quick/qquickitem | |
parent | c016634478a4c9f480f7d9d5c85dded307a80d13 (diff) |
Fix QQuickItem's setAcceptedMouseButtons function
When using setAcceptedMouseButtons to only allow the LeftButton, the
user can click the LeftButton and while still holding it press the
RightButton. There would be a press event sent for both. To resolve this,
a check needed to be added to ensure the acceptedMouseButtons are
checked when a second press comes in.
[ChangeLog][QtQuick][QQuickItem] Fixed issue with mouse button events
being sent even when they were disabled by setAcceptedMouseButtons.
Change-Id: I064f3ff56ede12b1572e172be326eb337e280750
Task-number: QTBUG-31861
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto/quick/qquickitem')
-rw-r--r-- | tests/auto/quick/qquickitem/tst_qquickitem.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickitem/tst_qquickitem.cpp b/tests/auto/quick/qquickitem/tst_qquickitem.cpp index 73e691b08c..6a49c4dd7e 100644 --- a/tests/auto/quick/qquickitem/tst_qquickitem.cpp +++ b/tests/auto/quick/qquickitem/tst_qquickitem.cpp @@ -172,6 +172,8 @@ private slots: void contains_data(); void contains(); + void ignoreButtonPressNotInAcceptedMouseButtons(); + private: enum PaintOrderOp { @@ -1971,6 +1973,27 @@ void tst_qquickitem::contains() QCOMPARE(result.toBool(), contains); } +void tst_qquickitem::ignoreButtonPressNotInAcceptedMouseButtons() +{ + // Verify the fix for QTBUG-31861 + TestItem item; + QCOMPARE(item.acceptedMouseButtons(), Qt::MouseButtons(Qt::NoButton)); + + QQuickWindow window; + item.setSize(QSizeF(200,100)); + item.setParentItem(window.contentItem()); + + item.setAcceptedMouseButtons(Qt::LeftButton); + QCOMPARE(item.acceptedMouseButtons(), Qt::MouseButtons(Qt::LeftButton)); + + QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(50, 50)); + QTest::mousePress(&window, Qt::RightButton, 0, QPoint(50, 50)); // ignored because it's not LeftButton + QTest::mouseRelease(&window, Qt::RightButton, 0, QPoint(50, 50)); // ignored because it didn't grab the RightButton press + QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(50, 50)); + + QCOMPARE(item.pressCount, 1); + QCOMPARE(item.releaseCount, 1); +} QTEST_MAIN(tst_qquickitem) |