diff --git a/src/widgets/graphicsview/qgraphicsproxywidget.cpp b/src/widgets/graphicsview/qgraphicsproxywidget.cpp index 08ea1ea0e3..edb0f4e0ff 100644 --- a/src/widgets/graphicsview/qgraphicsproxywidget.cpp +++ b/src/widgets/graphicsview/qgraphicsproxywidget.cpp @@ -879,6 +879,19 @@ bool QGraphicsProxyWidget::event(QEvent *event) break; } #endif + case QEvent::TouchBegin: + case QEvent::TouchUpdate: + case QEvent::TouchEnd: { + if (event->spontaneous()) + qt_sendSpontaneousEvent(d->widget, event); + else + QApplication::sendEvent(d->widget, event); + + if (event->isAccepted()) + return true; + + break; + } default: break; } diff --git a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp index 4896d52343..8760dc176c 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp @@ -179,6 +179,7 @@ private slots: void mapToGlobal(); void mapToGlobalWithoutScene(); void QTBUG_43780_visibility(); + void forwardTouchEvent(); }; // Subclass that exposes the protected functions. @@ -3760,5 +3761,73 @@ void tst_QGraphicsProxyWidget::QTBUG_43780_visibility() QVERIFY(comboPopup->isVisible()); } +class TouchWidget : public QWidget +{ +public: + TouchWidget(QWidget *parent = 0) : QWidget(parent) {} + + bool event(QEvent *event) + { + switch (event->type()) { + case QEvent::TouchBegin: + case QEvent::TouchUpdate: + case QEvent::TouchEnd: + event->accept(); + return true; + break; + default: + break; + } + + return QWidget::event(event); + } +}; + +// QTBUG_45737 +void tst_QGraphicsProxyWidget::forwardTouchEvent() +{ + QGraphicsScene *scene = new QGraphicsScene; + + TouchWidget *widget = new TouchWidget; + + widget->setAttribute(Qt::WA_AcceptTouchEvents); + + QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget; + + proxy->setAcceptTouchEvents(true); + proxy->setWidget(widget); + + scene->addItem(proxy); + + QGraphicsView *view = new QGraphicsView(scene); + + view->show(); + + EventSpy eventSpy(widget); + + QTouchDevice *device = new QTouchDevice; + device->setType(QTouchDevice::TouchScreen); + QWindowSystemInterface::registerTouchDevice(device); + + QCOMPARE(eventSpy.counts[QEvent::TouchBegin], 0); + QCOMPARE(eventSpy.counts[QEvent::TouchUpdate], 0); + QCOMPARE(eventSpy.counts[QEvent::TouchEnd], 0); + + QTest::touchEvent(view, device).press(0, QPoint(10, 10), view); + QTest::touchEvent(view, device).move(0, QPoint(15, 15), view); + QTest::touchEvent(view, device).move(0, QPoint(16, 16), view); + QTest::touchEvent(view, device).release(0, QPoint(15, 15), view); + + QApplication::processEvents(); + + QCOMPARE(eventSpy.counts[QEvent::TouchBegin], 1); + QCOMPARE(eventSpy.counts[QEvent::TouchUpdate], 2); + QCOMPARE(eventSpy.counts[QEvent::TouchEnd], 1); + + delete view; + delete proxy; + delete scene; +} + QTEST_MAIN(tst_QGraphicsProxyWidget) #include "tst_qgraphicsproxywidget.moc"