From 4cfa25b9669ebc56fda4b16e746a60ba31fe8188 Mon Sep 17 00:00:00 2001 From: Yuriy Puchkov Date: Mon, 25 Jan 2021 17:04:54 +0200 Subject: [PATCH] fix - MacOS - Grabbed color differs from the clicked area (cherry picked from commit 850d7f1df3c8a3fa9aa3db7beaba242abe78a855) --- src/widgets/panel/sidepanelwidget.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/widgets/panel/sidepanelwidget.cpp b/src/widgets/panel/sidepanelwidget.cpp index 1808917c..6c339afe 100644 --- a/src/widgets/panel/sidepanelwidget.cpp +++ b/src/widgets/panel/sidepanelwidget.cpp @@ -24,6 +24,11 @@ #include #include #include +#if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \ + defined(Q_OS_MACX)) +#include +#include +#endif class QColorPickingEventFilter : public QObject { @@ -161,8 +166,20 @@ QColor SidePanelWidget::grabPixmapColor(const QPoint& p) { QColor c; if (m_pixmap) { +#if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \ + defined(Q_OS_MACX)) + QScreen* currentScreen = QGuiApplication::screenAt(QCursor::pos()); + QPoint point = p; + if (currentScreen) { + point = QPoint((p.x() - currentScreen->geometry().x()) * + currentScreen->devicePixelRatio(), + (p.y() - currentScreen->geometry().y()) * + currentScreen->devicePixelRatio()); + } + QPixmap pixel = m_pixmap->copy(QRect(point, point)); +#else QPixmap pixel = m_pixmap->copy(QRect(p, p)); - c = pixel.toImage().pixel(0, 0); +#endif } return c; }