@@ -250,10 +250,14 @@ def leaveEvent(self, event):
250
250
QtWidgets .QApplication .restoreOverrideCursor ()
251
251
FigureCanvasBase .leave_notify_event (self , guiEvent = event )
252
252
253
+ def mouseEventCoords (self , pos ):
254
+ x = pos .x () * self .devicePixelRatio ()
255
+ # flip y so y=0 is bottom of canvas
256
+ y = self .figure .bbox .height - pos .y () * self .devicePixelRatio ()
257
+ return x , y
258
+
253
259
def mousePressEvent (self , event ):
254
- x = event .pos ().x ()
255
- # flipy so y=0 is bottom of canvas
256
- y = self .figure .bbox .height - event .pos ().y ()
260
+ x , y = self .mouseEventCoords (event .pos ())
257
261
button = self .buttond .get (event .button ())
258
262
if button is not None :
259
263
FigureCanvasBase .button_press_event (self , x , y , button ,
@@ -262,9 +266,7 @@ def mousePressEvent(self, event):
262
266
print ('button pressed:' , event .button ())
263
267
264
268
def mouseDoubleClickEvent (self , event ):
265
- x = event .pos ().x ()
266
- # flipy so y=0 is bottom of canvas
267
- y = self .figure .bbox .height - event .pos ().y ()
269
+ x , y = self .mouseEventCoords (event .pos ())
268
270
button = self .buttond .get (event .button ())
269
271
if button is not None :
270
272
FigureCanvasBase .button_press_event (self , x , y ,
@@ -274,16 +276,12 @@ def mouseDoubleClickEvent(self, event):
274
276
print ('button doubleclicked:' , event .button ())
275
277
276
278
def mouseMoveEvent (self , event ):
277
- x = event .x ()
278
- # flipy so y=0 is bottom of canvas
279
- y = self .figure .bbox .height - event .y ()
279
+ x , y = self .mouseEventCoords (event )
280
280
FigureCanvasBase .motion_notify_event (self , x , y , guiEvent = event )
281
281
# if DEBUG: print('mouse move')
282
282
283
283
def mouseReleaseEvent (self , event ):
284
- x = event .x ()
285
- # flipy so y=0 is bottom of canvas
286
- y = self .figure .bbox .height - event .y ()
284
+ x , y = self .mouseEventCoords (event )
287
285
button = self .buttond .get (event .button ())
288
286
if button is not None :
289
287
FigureCanvasBase .button_release_event (self , x , y , button ,
@@ -292,9 +290,7 @@ def mouseReleaseEvent(self, event):
292
290
print ('button released' )
293
291
294
292
def wheelEvent (self , event ):
295
- x = event .x ()
296
- # flipy so y=0 is bottom of canvas
297
- y = self .figure .bbox .height - event .y ()
293
+ x , y = self .mouseEventCoords (event )
298
294
# from QWheelEvent::delta doc
299
295
if event .pixelDelta ().x () == 0 and event .pixelDelta ().y () == 0 :
300
296
steps = event .angleDelta ().y () / 120
@@ -324,8 +320,9 @@ def keyReleaseEvent(self, event):
324
320
print ('key release' , key )
325
321
326
322
def resizeEvent (self , event ):
327
- w = event .size ().width ()
328
- h = event .size ().height ()
323
+ dpi_ratio = getattr (self , '_dpi_ratio' , 1 )
324
+ w = event .size ().width () * dpi_ratio
325
+ h = event .size ().height () * dpi_ratio
329
326
if DEBUG :
330
327
print ('resize (%d x %d)' % (w , h ))
331
328
print ("FigureCanvasQt.resizeEvent(%d, %d)" % (w , h ))
0 commit comments