Skip to content

Commit 20db05d

Browse files
committed
Fix High DPI issues with new color picker
1 parent 76068c3 commit 20db05d

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/windows/color_picker.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class PickingDialog(QDialog):
8282
def __init__(self, pixmap, color_picker, *args, **kwargs):
8383
super().__init__(*args, **kwargs)
8484
self.pixmap = pixmap
85+
self.device_pixel_ratio = pixmap.devicePixelRatio()
8586
self.color_picker = color_picker
8687
self.setWindowModality(Qt.WindowModal)
8788
self.setGeometry(get_app().window.geometry())
@@ -105,16 +106,22 @@ def paintEvent(self, event):
105106
def mouseMoveEvent(self, event):
106107
if self.pixmap:
107108
image = self.pixmap.toImage()
108-
if 0 <= event.x() < image.width() and 0 <= event.y() < image.height():
109-
color = QColor(image.pixel(event.pos()))
109+
# Scale the coordinates for High DPI displays
110+
scaled_x = int(event.x() * self.device_pixel_ratio)
111+
scaled_y = int(event.y() * self.device_pixel_ratio)
112+
if 0 <= scaled_x < image.width() and 0 <= scaled_y < image.height():
113+
color = QColor(image.pixel(scaled_x, scaled_y))
110114
self.color_preview = color
111115
self.update()
112116

113117
def mousePressEvent(self, event):
114118
if self.pixmap:
115119
image = self.pixmap.toImage()
116-
if 0 <= event.x() < image.width() and 0 <= event.y() < image.height():
117-
color = QColor(image.pixel(event.pos()))
120+
# Scale the coordinates for High DPI displays
121+
scaled_x = int(event.x() * self.device_pixel_ratio)
122+
scaled_y = int(event.y() * self.device_pixel_ratio)
123+
if 0 <= scaled_x < image.width() and 0 <= scaled_y < image.height():
124+
color = QColor(image.pixel(scaled_x, scaled_y))
118125
self.color_picker.setCurrentColor(color)
119126
log.debug(f"Picked color: {color.name()}")
120127
self.accept() # Close the dialog

0 commit comments

Comments
 (0)