From da5d71c23c31e89db59006183a3572d35e3c85d1 Mon Sep 17 00:00:00 2001 From: borgmanJeremy <46930769+borgmanJeremy@users.noreply.github.com> Date: Fri, 24 Dec 2021 14:36:39 -0600 Subject: [PATCH] Fixed an issue where the magnifier did not account for hiDPI on retina screens (#2187) --- src/widgets/panel/colorgrabwidget.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/widgets/panel/colorgrabwidget.cpp b/src/widgets/panel/colorgrabwidget.cpp index 59a56ef3..1d817528 100644 --- a/src/widgets/panel/colorgrabwidget.cpp +++ b/src/widgets/panel/colorgrabwidget.cpp @@ -200,11 +200,26 @@ void ColorGrabWidget::updateWidget() float zoom = m_extraZoomActive ? ZOOM2 : ZOOM1; // Set window size and move its center to the mouse cursor QRect rect(0, 0, width, width); + + auto realCursorPos = cursorPos(); + auto adjustedCursorPos = realCursorPos; + +#if defined(Q_OS_MACOS) + QScreen* currentScreen = QGuiAppCurrentScreen().currentScreen(); + if (currentScreen) { + adjustedCursorPos = + QPoint((realCursorPos.x() - currentScreen->geometry().x()) * + currentScreen->devicePixelRatio(), + (realCursorPos.y() - currentScreen->geometry().y()) * + currentScreen->devicePixelRatio()); + } +#endif + rect.moveCenter(cursorPos()); setGeometry(rect); // Store a pixmap containing the zoomed-in section around the cursor QRect sourceRect(0, 0, width / zoom, width / zoom); - sourceRect.moveCenter(rect.center()); + sourceRect.moveCenter(adjustedCursorPos); m_previewImage = m_pixmap->copy(sourceRect).toImage(); // Repaint update();