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