diff --git a/lib/matplotlib/backends/backend_qt4.py b/lib/matplotlib/backends/backend_qt4.py index 45fe444743d8..7224ebce6074 100644 --- a/lib/matplotlib/backends/backend_qt4.py +++ b/lib/matplotlib/backends/backend_qt4.py @@ -497,6 +497,9 @@ def __init__(self, canvas, parent, coordinates=True): """ coordinates: should we show the coordinates on the right? """ self.canvas = canvas self.coordinates = coordinates + self._actions = {} + """A mapping of toolitem method names to their QActions""" + QtGui.QToolBar.__init__( self, parent ) NavigationToolbar2.__init__( self, canvas ) @@ -512,6 +515,9 @@ def _init_toolbar(self): else: a = self.addAction(self._icon(image_file + '.png'), text, getattr(self, callback)) + self._actions[callback] = a + if callback in ['zoom', 'pan']: + a.setCheckable(True) if tooltip_text is not None: a.setToolTip(tooltip_text) @@ -570,6 +576,18 @@ def edit_parameters(self): figureoptions.figure_edit(axes, self) + def _update_buttons_checked(self): + #sync button checkstates to match active mode + self._actions['pan'].setChecked(self._active == 'PAN') + self._actions['zoom'].setChecked(self._active == 'ZOOM') + + def pan(self, *args): + super(NavigationToolbar2QT, self).pan(*args) + self._update_buttons_checked() + + def zoom(self, *args): + super(NavigationToolbar2QT, self).zoom(*args) + self._update_buttons_checked() def dynamic_update( self ): self.canvas.draw()