From 21355b3630882932be940a48a88d8c40cf7ebf63 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 26 Sep 2018 17:36:04 +0200 Subject: QGraphicsScene: Make focusing on touchBegin optional Usually we focus in when we receive a click or equivalent. QGraphicsScene by default also transfers the focus when you start a touch on a trackpad or similar. Most of the time this also generates a synthetic mouse click, so people don't necessary notice. However, at least on macOS you can configure this behavior. With focusOnTouch switched off, QGraphicsScene behaves as one would expect on macOS. Fixes: QTBUG-59442 Change-Id: Ib87112640eef6b77892ad2490d80eedd055e6dce Reviewed-by: Paul Wicking Reviewed-by: Venugopal Shivashankar Reviewed-by: Shawn Rutledge --- .../qgraphicsscene/tst_qgraphicsscene.cpp | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp index c8ee2d65a3..838b1f4be6 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp @@ -254,6 +254,7 @@ private slots: void zeroScale(); void focusItemChangedSignal(); void minimumRenderSize(); + void focusOnTouch(); // task specific tests below me void task139710_bspTreeCrash(); @@ -4758,6 +4759,41 @@ void tst_QGraphicsScene::minimumRenderSize() QVERIFY(smallChild->repaints > smallerGrandChild->repaints); } +void tst_QGraphicsScene::focusOnTouch() +{ + QGraphicsScene scene; + QGraphicsView view(&scene); + scene.setSceneRect(0, 0, 100, 100); + QGraphicsRectItem *rect = scene.addRect(0, 0, 100, 100); + rect->setFlag(QGraphicsItem::ItemIsFocusable, true); + + view.show(); + QApplication::setActiveWindow(&view); + QVERIFY(QTest::qWaitForWindowActive(&view)); + + QVERIFY(!rect->hasFocus()); + + scene.setFocusOnTouch(false); + + QTouchDevice device; + device.setType(QTouchDevice::TouchPad); + QList touchPoints; + QTouchEvent::TouchPoint point; + point.setScenePos(QPointF(10, 10)); + point.setState(Qt::TouchPointPressed); + touchPoints.append(point); + QTouchEvent event(QEvent::TouchBegin, &device, Qt::NoModifier, Qt::TouchPointStates(), + touchPoints); + + QApplication::sendEvent(&scene, &event); + + QVERIFY(!rect->hasFocus()); + scene.setFocusOnTouch(true); + + QApplication::sendEvent(&scene, &event); + QVERIFY(rect->hasFocus()); +} + void tst_QGraphicsScene::taskQTBUG_15977_renderWithDeviceCoordinateCache() { QGraphicsScene scene; -- cgit v1.2.3