@@ -61,7 +61,8 @@ OcctQWidgetViewer::OcctQWidgetViewer(QWidget* theParent)
6161 // Qt widget setup
6262 setAttribute (Qt::WA_PaintOnScreen);
6363 setAttribute (Qt::WA_NoSystemBackground);
64- setAttribute (Qt::WA_NativeWindow); // request native window for this widget to create OpenGL context
64+ setAttribute (Qt::WA_NativeWindow); // request native window for this widget to create OpenGL context
65+ setAttribute (Qt::WA_AcceptTouchEvents); // necessary to recieve QTouchEvent events
6566 setMouseTracking (true );
6667 setBackgroundRole (QPalette::NoRole); // or NoBackground
6768 setFocusPolicy (Qt::StrongFocus); // set focus policy to threat QContextMenuEvent from keyboard
@@ -150,6 +151,53 @@ void OcctQWidgetViewer::initializeGL()
150151 }
151152}
152153
154+ // ================================================================
155+ // Function : event
156+ // ================================================================
157+ bool OcctQWidgetViewer::event (QEvent* theEvent)
158+ {
159+ if (myView.IsNull ())
160+ return QWidget::event (theEvent);
161+
162+ const bool isTouch = theEvent->type () == QEvent::TouchBegin
163+ || theEvent->type () == QEvent::TouchUpdate
164+ || theEvent->type () == QEvent::TouchEnd;
165+ if (!isTouch)
166+ return QWidget::event (theEvent);
167+
168+ bool hasUpdates = false ;
169+ const QTouchEvent* aQTouchEvent = static_cast <QTouchEvent*>(theEvent);
170+ for (const QTouchEvent::TouchPoint& aQTouch : aQTouchEvent->touchPoints ())
171+ {
172+ const Standard_Size aTouchId = aQTouch.id ();
173+ const Graphic3d_Vec2d aNewPos2d (aQTouch.pos ().x (), aQTouch.pos ().y ());
174+ const Graphic3d_Vec2i aNewPos2i = Graphic3d_Vec2i (aNewPos2d + Graphic3d_Vec2d (0.5 ));
175+ if (aQTouch.state () == Qt::TouchPointPressed
176+ && aNewPos2i.minComp () >= 0 )
177+ {
178+ hasUpdates = true ;
179+ AddTouchPoint (aTouchId, aNewPos2d);
180+ }
181+ else if (aQTouch.state () == Qt::TouchPointMoved
182+ && TouchPoints ().Contains (aTouchId))
183+ {
184+ hasUpdates = true ;
185+ UpdateTouchPoint (aTouchId, aNewPos2d);
186+ }
187+ else if (aQTouch.state () == Qt::TouchPointReleased
188+ && RemoveTouchPoint (aTouchId))
189+ {
190+ hasUpdates = true ;
191+ }
192+ }
193+
194+ myHasTouchInput = true ;
195+ if (hasUpdates)
196+ updateView ();
197+
198+ return true ;
199+ }
200+
153201// ================================================================
154202// Function : closeEvent
155203// ================================================================
@@ -191,6 +239,9 @@ void OcctQWidgetViewer::mousePressEvent(QMouseEvent* theEvent)
191239 if (myView.IsNull ())
192240 return ;
193241
242+ if (myHasTouchInput && theEvent->source () == Qt::MouseEventSynthesizedBySystem)
243+ return ; // skip mouse events emulated by system from screen touches
244+
194245 const Graphic3d_Vec2i aPnt (theEvent->pos ().x (), theEvent->pos ().y ());
195246 const Aspect_VKeyFlags aFlags = OcctQtTools::qtMouseModifiers2VKeys (theEvent->modifiers ());
196247 if (UpdateMouseButtons (aPnt, OcctQtTools::qtMouseButtons2VKeys (theEvent->buttons ()), aFlags, false ))
@@ -221,6 +272,9 @@ void OcctQWidgetViewer::mouseMoveEvent(QMouseEvent* theEvent)
221272 if (myView.IsNull ())
222273 return ;
223274
275+ if (myHasTouchInput && theEvent->source () == Qt::MouseEventSynthesizedBySystem)
276+ return ; // skip mouse events emulated by system from screen touches
277+
224278 const Graphic3d_Vec2i aNewPos (theEvent->pos ().x (), theEvent->pos ().y ());
225279 if (UpdateMousePosition (aNewPos,
226280 OcctQtTools::qtMouseButtons2VKeys (theEvent->buttons ()),
0 commit comments