3232import matplotlib .path as mpath
3333import matplotlib .text as mtext
3434import matplotlib .transforms as mtransforms
35+ from matplotlib .backend_tools import Cursors
3536from matplotlib .font_manager import FontProperties
3637from matplotlib .image import BboxImage
3738from matplotlib .patches import (
@@ -1485,6 +1486,7 @@ def __init__(self, ref_artist, use_blit=False):
14851486 if not ref_artist .pickable ():
14861487 ref_artist .set_picker (True )
14871488 self .got_artist = False
1489+ self ._hover = False
14881490 self ._use_blit = use_blit and self .canvas .supports_blit
14891491 callbacks = ref_artist .figure ._canvas_callbacks
14901492 self ._disconnectors = [
@@ -1504,6 +1506,33 @@ def __init__(self, ref_artist, use_blit=False):
15041506 disconnect .args [0 ] for disconnect in self ._disconnectors [:2 ]])
15051507
15061508 def on_motion (self , evt ):
1509+ # Only check if the widget lock is available, setting it would prevent
1510+ # picking.
1511+ if not (
1512+ self ._check_still_parented () and self .canvas .widgetlock .available (self )
1513+ ):
1514+ return
1515+
1516+ picker = self .ref_artist .get_picker ()
1517+ if callable (picker ):
1518+ inside , _ = picker (self , evt )
1519+ else :
1520+ inside , _ = self .ref_artist .contains (evt )
1521+
1522+ # If the mouse is moving quickly while dragging, it may leave the artist,
1523+ # but should still use the move cursor.
1524+ if inside or self .got_artist :
1525+ # Ideally, this should use an open hand cursor on hover, and a closed
1526+ # hand when dragging, but those cursors are not natively provided by
1527+ # all platforms.
1528+ self ._hover = True
1529+ self .canvas .set_cursor (Cursors .MOVE )
1530+ elif self ._hover :
1531+ # Only change the cursor back if this is the widget that set it, to
1532+ # avoid multiple draggable widgets fighting over the cursor.
1533+ self ._hover = False
1534+ self .canvas .set_cursor (Cursors .POINTER )
1535+
15071536 if self ._check_still_parented () and self .got_artist :
15081537 dx = evt .x - self .mouse_x
15091538 dy = evt .y - self .mouse_y
@@ -1550,6 +1579,9 @@ def disconnect(self):
15501579 for disconnector in self ._disconnectors :
15511580 disconnector ()
15521581
1582+ if self ._hover :
1583+ self .canvas .set_cursor (Cursors .POINTER )
1584+
15531585 def save_offset (self ):
15541586 pass
15551587
0 commit comments