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 Change-Id: I09168b597f6c43a119041d00f5b07e1895fdf4b3 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> (cherry picked from commit ff83fc75901527c0c14c481dbe9929129942c5b9) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
ffe98c9b51
commit
2aef2eb522
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user