fix - MacOS - Grabbed color differs from the clicked area

(cherry picked from commit 850d7f1df3c8a3fa9aa3db7beaba242abe78a855)
This commit is contained in:
Yuriy Puchkov
2021-01-25 17:04:54 +02:00
parent 7913d4ac04
commit 4cfa25b966

View File

@@ -24,6 +24,11 @@
#include <QPushButton>
#include <QSlider>
#include <QVBoxLayout>
#if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \
defined(Q_OS_MACX))
#include <QGuiApplication>
#include <QScreen>
#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;
}