@@ -82,6 +82,7 @@ class PickingDialog(QDialog):
82
82
def __init__ (self , pixmap , color_picker , * args , ** kwargs ):
83
83
super ().__init__ (* args , ** kwargs )
84
84
self .pixmap = pixmap
85
+ self .device_pixel_ratio = pixmap .devicePixelRatio ()
85
86
self .color_picker = color_picker
86
87
self .setWindowModality (Qt .WindowModal )
87
88
self .setGeometry (get_app ().window .geometry ())
@@ -105,16 +106,22 @@ def paintEvent(self, event):
105
106
def mouseMoveEvent (self , event ):
106
107
if self .pixmap :
107
108
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 ))
110
114
self .color_preview = color
111
115
self .update ()
112
116
113
117
def mousePressEvent (self , event ):
114
118
if self .pixmap :
115
119
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 ))
118
125
self .color_picker .setCurrentColor (color )
119
126
log .debug (f"Picked color: { color .name ()} " )
120
127
self .accept () # Close the dialog
0 commit comments