File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -239,6 +239,7 @@ def __init__(self, figure=None):
239
239
240
240
self .setAttribute (QtCore .Qt .WidgetAttribute .WA_OpaquePaintEvent )
241
241
self .setMouseTracking (True )
242
+ self .mouse_xy = (0 , 0 )
242
243
self .resize (* self .get_width_height ())
243
244
244
245
palette = QtGui .QPalette (QtGui .QColor ("white" ))
@@ -344,8 +345,10 @@ def mouseDoubleClickEvent(self, event):
344
345
def mouseMoveEvent (self , event ):
345
346
if self .figure is None :
346
347
return
348
+ self .mouse_xy = self .mouseEventCoords (event )
349
+ self .repaint ()
347
350
MouseEvent ("motion_notify_event" , self ,
348
- * self .mouseEventCoords ( event ) ,
351
+ * self .mouse_xy ,
349
352
buttons = self ._mpl_buttons (event .buttons ()),
350
353
modifiers = self ._mpl_modifiers (),
351
354
guiEvent = event )._process ()
Original file line number Diff line number Diff line change @@ -68,6 +68,19 @@ def paintEvent(self, event):
68
68
ctypes .c_long .from_address (id (buf )).value = 1
69
69
70
70
self ._draw_rect_callback (painter )
71
+
72
+ figx = self .mouse_xy [0 ] / rect .width ()
73
+ figy = 1 - self .mouse_xy [1 ] / rect .height ()
74
+ x0 = rect .left ()
75
+ x1 = rect .left () + rect .width ()
76
+ y0 = rect .top ()
77
+ y1 = rect .top () + rect .height ()
78
+ x = rect .left () + int (figx * rect .width ())
79
+ y = rect .top () + int (figy * rect .height ())
80
+ painter .setPen (QtGui .QPen (QtCore .Qt .GlobalColor .red ))
81
+ painter .drawLine (x0 , y , x1 , y )
82
+ painter .drawLine (x , y0 , x , y1 )
83
+
71
84
finally :
72
85
painter .end ()
73
86
You can’t perform that action at this time.
0 commit comments