From ff83fc75901527c0c14c481dbe9929129942c5b9 Mon Sep 17 00:00:00 2001 From: Axel Spoerl Date: Fri, 16 Dec 2022 10:37:00 +0100 Subject: [PATCH] Map toolbar drag delta from native pixels MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The delta (drag distance) for dragging a tool button with in a tool bar was calculated by subtracting the global mouse press position from the drag event's global position. This has lead to a miscalculation when dragging the button across screens with different resolutions. The new relative position within the tool bar became negative, which eventually has lead to resizing of other tool buttons in the same tool bar. This patch calculates the delta based on native pixels, which ensures a correct value in all cases. It falls back to the existing calculation if no window handle can be established from the tool bar. Fixes: QTBUG-103720 Pick-to: 6.5 Change-Id: I09168b597f6c43a119041d00f5b07e1895fdf4b3 Reviewed-by: Morten Johan Sørvig --- src/widgets/widgets/qtoolbar.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/widgets/widgets/qtoolbar.cpp b/src/widgets/widgets/qtoolbar.cpp index ae0414e7764..b5950fdf238 100644 --- a/src/widgets/widgets/qtoolbar.cpp +++ b/src/widgets/widgets/qtoolbar.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #ifdef Q_OS_MACOS #include @@ -309,7 +310,12 @@ bool QToolBarPrivate::mouseMoveEvent(QMouseEvent *event) const QPoint globalPressPos = q->mapToGlobal(q->isRightToLeft() ? rtl : state->pressPos); int pos = 0; - QPoint delta = event->globalPosition().toPoint() - globalPressPos; + const QWindow *handle = q->window() ? q->window()->windowHandle() : nullptr; + const QPoint delta = handle + ? QHighDpi::fromNativePixels(event->globalPosition(), handle).toPoint() + - QHighDpi::fromNativePixels(globalPressPos, handle) + : event->globalPosition().toPoint() - globalPressPos; + if (orientation == Qt::Vertical) { pos = q->y() + delta.y(); } else {