From 5feb391a9dc0608d96bf0817f5eb193f36ea2838 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 13 Feb 2025 11:17:05 -0500 Subject: [PATCH] Read colorpicker screen using cursor position --- include/ui/colorpicker.h | 2 +- src/ui/colorpicker.cpp | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/ui/colorpicker.h b/include/ui/colorpicker.h index fa431341..69a6c9b2 100644 --- a/include/ui/colorpicker.h +++ b/include/ui/colorpicker.h @@ -27,7 +27,7 @@ private: QColor color = Qt::white; - void hover(int mouseX, int mouseY); + void hover(const QPoint &pos); }; #endif // COLORPICKER_H diff --git a/src/ui/colorpicker.cpp b/src/ui/colorpicker.cpp index dccffc0e..5d2d3992 100644 --- a/src/ui/colorpicker.cpp +++ b/src/ui/colorpicker.cpp @@ -27,7 +27,7 @@ ColorPicker::ColorPicker(QWidget *parent) : QPoint cursorPos = QCursor::pos(); if (lastCursorPos != cursorPos) { lastCursorPos = cursorPos; - this->hover(cursorPos.x(), cursorPos.y()); + this->hover(cursorPos); } }); timer->start(10); @@ -40,15 +40,17 @@ ColorPicker::~ColorPicker() delete ui; } -void ColorPicker::hover(int mouseX, int mouseY) { - QScreen *screen = QGuiApplication::primaryScreen(); - if (const QWindow *window = windowHandle()) - screen = window->screen(); +void ColorPicker::hover(const QPoint &pos) { + QScreen *screen = QGuiApplication::screenAt(pos); + if (!screen) { + const QWindow *window = windowHandle(); + if (window) screen = window->screen(); + } if (!screen) return; // 15 X 15 box with 8x magnification = 120px square) - QPixmap grab = screen->grabWindow(0, mouseX - zoom_box_dimensions / 2, mouseY - zoom_box_dimensions / 2, zoom_box_dimensions, zoom_box_dimensions); + QPixmap grab = screen->grabWindow(0, pos.x() - zoom_box_dimensions / 2, pos.y() - zoom_box_dimensions / 2, zoom_box_dimensions, zoom_box_dimensions); int pixelRatio = grab.devicePixelRatio(); // TODO: investigate for high dpi displays why text is too high res