From 8b91afe12e2b53d1fccded1e91cdc3e4290042b2 Mon Sep 17 00:00:00 2001 From: Christian Andersen Date: Tue, 18 Dec 2018 00:08:38 +0100 Subject: [PATCH] QMdiSubWindow: Avoid potential shaking motion when moving window When using QMouseEvent::pos to change the position of a widget, the widget may shift in a shaking motion. This is warned about in its documentation. For example if the system has a bit of load, we might receive multiple mouse move events from the OS, before QMdiSubWindow gets the first move event. In that case the first mouse move is ok, but subsequent move events, will use a ::pos value that now does not make sense as the position of the window have changed. The fix is to use QMouseEvent::globalPos. Fixes: QTBUG-72646 Change-Id: I3211cc6627ff8fe26c9520ad0457872f01c32471 Reviewed-by: Andre de la Rocha Reviewed-by: Richard Moe Gustavsen --- src/widgets/widgets/qmdisubwindow.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/widgets/widgets/qmdisubwindow.cpp b/src/widgets/widgets/qmdisubwindow.cpp index 794674c427..1ed162482e 100644 --- a/src/widgets/widgets/qmdisubwindow.cpp +++ b/src/widgets/widgets/qmdisubwindow.cpp @@ -3341,8 +3341,11 @@ void QMdiSubWindow::mouseMoveEvent(QMouseEvent *mouseEvent) } if ((mouseEvent->buttons() & Qt::LeftButton) || d->isInInteractiveMode) { - if ((d->isResizeOperation() && d->resizeEnabled) || (d->isMoveOperation() && d->moveEnabled)) - d->setNewGeometry(mapToParent(mouseEvent->pos())); + if ((d->isResizeOperation() && d->resizeEnabled) || (d->isMoveOperation() && d->moveEnabled)) { + // As setNewGeometry moves the window, it invalidates the pos() value of any mouse move events that are + // currently queued in the event loop. Map to parent using globalPos() instead. + d->setNewGeometry(parentWidget()->mapFromGlobal(mouseEvent->globalPos())); + } return; }