Skip to content

Commit 720a0e8

Browse files
committed
QWidget samples - add missing accept() to mouse events
Fixes unexpected dragging of entire window on Linux.
1 parent 572a5de commit 720a0e8

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

occt-qopenglwidget/OcctQOpenGLWidgetViewer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ void OcctQOpenGLWidgetViewer::keyPressEvent(QKeyEvent* theEvent)
242242
case Aspect_VKey_F: {
243243
myView->FitAll(0.01, false);
244244
update();
245+
theEvent->accept();
245246
return;
246247
}
247248
}
@@ -260,6 +261,7 @@ void OcctQOpenGLWidgetViewer::mousePressEvent(QMouseEvent* theEvent)
260261
if (myHasTouchInput && theEvent->source() == Qt::MouseEventSynthesizedBySystem)
261262
return; // skip mouse events emulated by system from screen touches
262263

264+
theEvent->accept();
263265
const Graphic3d_Vec2i aPnt(theEvent->pos().x(), theEvent->pos().y());
264266
const Aspect_VKeyMouse aButtons = OcctQtTools::qtMouseButtons2VKeys(theEvent->buttons());
265267
const Aspect_VKeyFlags aFlags = OcctQtTools::qtMouseModifiers2VKeys(theEvent->modifiers());
@@ -276,6 +278,7 @@ void OcctQOpenGLWidgetViewer::mouseReleaseEvent(QMouseEvent* theEvent)
276278
if (myView.IsNull())
277279
return;
278280

281+
theEvent->accept();
279282
const Graphic3d_Vec2i aPnt(theEvent->pos().x(), theEvent->pos().y());
280283
const Aspect_VKeyMouse aButtons = OcctQtTools::qtMouseButtons2VKeys(theEvent->buttons());
281284
const Aspect_VKeyFlags aFlags = OcctQtTools::qtMouseModifiers2VKeys(theEvent->modifiers());
@@ -295,6 +298,7 @@ void OcctQOpenGLWidgetViewer::mouseMoveEvent(QMouseEvent* theEvent)
295298
if (myHasTouchInput && theEvent->source() == Qt::MouseEventSynthesizedBySystem)
296299
return; // skip mouse events emulated by system from screen touches
297300

301+
theEvent->accept();
298302
const Graphic3d_Vec2i aNewPos(theEvent->pos().x(), theEvent->pos().y());
299303
const Aspect_VKeyMouse aButtons = OcctQtTools::qtMouseButtons2VKeys(theEvent->buttons());
300304
const Aspect_VKeyFlags aFlags = OcctQtTools::qtMouseModifiers2VKeys(theEvent->modifiers());
@@ -311,6 +315,7 @@ void OcctQOpenGLWidgetViewer::wheelEvent(QWheelEvent* theEvent)
311315
if (myView.IsNull())
312316
return;
313317

318+
theEvent->accept();
314319
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
315320
const Graphic3d_Vec2i aPos(Graphic3d_Vec2d(theEvent->position().x(), theEvent->position().y()));
316321
#else

occt-qwidget/OcctQWidgetViewer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ bool OcctQWidgetViewer::event(QEvent* theEvent)
176176
if (!isTouch)
177177
return QWidget::event(theEvent);
178178

179+
theEvent->accept();
179180
bool hasUpdates = false;
180181
const QTouchEvent* aQTouchEvent = static_cast<QTouchEvent*>(theEvent);
181182
for (const QTouchEvent::TouchPoint& aQTouch : aQTouchEvent->touchPoints())
@@ -237,6 +238,7 @@ void OcctQWidgetViewer::keyPressEvent(QKeyEvent* theEvent)
237238
{
238239
myView->FitAll(0.01, false);
239240
update();
241+
theEvent->accept();
240242
return;
241243
}
242244
}
@@ -255,6 +257,7 @@ void OcctQWidgetViewer::mousePressEvent(QMouseEvent* theEvent)
255257
if (myHasTouchInput && theEvent->source() == Qt::MouseEventSynthesizedBySystem)
256258
return; // skip mouse events emulated by system from screen touches
257259

260+
theEvent->accept();
258261
const Graphic3d_Vec2i aPnt(theEvent->pos().x(), theEvent->pos().y());
259262
const Aspect_VKeyMouse aButtons = OcctQtTools::qtMouseButtons2VKeys(theEvent->buttons());
260263
const Aspect_VKeyFlags aFlags = OcctQtTools::qtMouseModifiers2VKeys(theEvent->modifiers());
@@ -271,6 +274,7 @@ void OcctQWidgetViewer::mouseReleaseEvent(QMouseEvent* theEvent)
271274
if (myView.IsNull())
272275
return;
273276

277+
theEvent->accept();
274278
const Graphic3d_Vec2i aPnt(theEvent->pos().x(), theEvent->pos().y());
275279
const Aspect_VKeyMouse aButtons = OcctQtTools::qtMouseButtons2VKeys(theEvent->buttons());
276280
const Aspect_VKeyFlags aFlags = OcctQtTools::qtMouseModifiers2VKeys(theEvent->modifiers());
@@ -290,6 +294,7 @@ void OcctQWidgetViewer::mouseMoveEvent(QMouseEvent* theEvent)
290294
if (myHasTouchInput && theEvent->source() == Qt::MouseEventSynthesizedBySystem)
291295
return; // skip mouse events emulated by system from screen touches
292296

297+
theEvent->accept();
293298
const Graphic3d_Vec2i aNewPos(theEvent->pos().x(), theEvent->pos().y());
294299
const Aspect_VKeyMouse aButtons = OcctQtTools::qtMouseButtons2VKeys(theEvent->buttons());
295300
const Aspect_VKeyFlags aFlags = OcctQtTools::qtMouseModifiers2VKeys(theEvent->modifiers());
@@ -306,6 +311,7 @@ void OcctQWidgetViewer::wheelEvent(QWheelEvent* theEvent)
306311
if (myView.IsNull())
307312
return;
308313

314+
theEvent->accept();
309315
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
310316
const Graphic3d_Vec2i aPos(Graphic3d_Vec2d(theEvent->position().x(), theEvent->position().y()));
311317
#else

0 commit comments

Comments
 (0)