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):
239239
240240 self .setAttribute (QtCore .Qt .WidgetAttribute .WA_OpaquePaintEvent )
241241 self .setMouseTracking (True )
242+ self .mouse_xy = (0 , 0 )
242243 self .resize (* self .get_width_height ())
243244
244245 palette = QtGui .QPalette (QtGui .QColor ("white" ))
@@ -344,8 +345,10 @@ def mouseDoubleClickEvent(self, event):
344345 def mouseMoveEvent (self , event ):
345346 if self .figure is None :
346347 return
348+ self .mouse_xy = self .mouseEventCoords (event )
349+ self .repaint ()
347350 MouseEvent ("motion_notify_event" , self ,
348- * self .mouseEventCoords ( event ) ,
351+ * self .mouse_xy ,
349352 buttons = self ._mpl_buttons (event .buttons ()),
350353 modifiers = self ._mpl_modifiers (),
351354 guiEvent = event )._process ()
Original file line number Diff line number Diff line change @@ -68,6 +68,19 @@ def paintEvent(self, event):
6868 ctypes .c_long .from_address (id (buf )).value = 1
6969
7070 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+
7184 finally :
7285 painter .end ()
7386
You can’t perform that action at this time.
0 commit comments