summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Spoerl <axel.spoerl@qt.io>2022-12-16 10:37:00 +0100
committerAxel Spoerl <axel.spoerl@qt.io>2022-12-19 21:16:38 +0100
commitff83fc75901527c0c14c481dbe9929129942c5b9 (patch)
tree1642fcd86cdb8d8b7433cecdb67bc67cbc2f67a0
parent13053d455ec3ff114d08795a63dae130b57d1578 (diff)
Map toolbar drag delta from native pixels
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 <morten.sorvig@qt.io>
-rw-r--r--src/widgets/widgets/qtoolbar.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/widgets/widgets/qtoolbar.cpp b/src/widgets/widgets/qtoolbar.cpp
index ae0414e776..b5950fdf23 100644
--- a/src/widgets/widgets/qtoolbar.cpp
+++ b/src/widgets/widgets/qtoolbar.cpp
@@ -24,6 +24,7 @@
#include <qtimer.h>
#include <private/qwidgetaction_p.h>
#include <private/qmainwindowlayout_p.h>
+#include <private/qhighdpiscaling_p.h>
#ifdef Q_OS_MACOS
#include <qpa/qplatformnativeinterface.h>
@@ -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 {