Matplotlib Navigation Toolbar: Remove "Change Line and Axis Settings"

Recently, I began to study interface development in Qt Designer and editing them through PyQt. Everything is going pretty smoothly, but I'm currently stuck trying to solve the following problem:

I inserted the MatplotLib widget through Qt Designer and managed to build pretty good horizontal bars using barh. Then I tried and successfully removed the functional NavigationToolBar via matplotlib.backends.backend_qt4agg.NavigationToolbar2QT

Then, after this stream (and the like), I managed to edit which buttons I would like to display on the toolbar ... How easy is it to change the navigation bar in matplotlib Figure window?

This works well for every button except the last one, with a checkmark drawing that describes โ€œEdit parameters of lines and axes of a curveโ€. In this particular case, I would really like to remove this button, because it constantly changes the size of the graph when moving the mouse, and in this case I do not need this button.

I have not yet found a single discussion topic for this button on the toolbar (only this matplotlib: annoying Qt4Agg toolbar error )

The code currently used to insert the toolbar and edit buttons looks something like this:

from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT class currentUI(QtGui.QWidget): def __init__(self): super(currentUI,self).__init__() (...) uic.loadUi('portfolioManager.ui',self) self.initUI() (...) def initUI(self): self.setWidgetsPropertiesAndActions() (...) def setWidgetsPropertiesAndActions(self): (...) self.navi_toolbar=NavigationToolbar(self.mplwidgetExposures, self) self.LayoutPlot.addWidget(self.navi_toolbar) (...) class NavigationToolbar(NavigationToolbar2QT): toolitems = [t for t in NavigationToolbar2QT.toolitems if t[0] in ('Home','Pan', 'Zoom', 'Save','Subplots')] 

This successfully implements the toolbar, but the "edit" button remains.

Thank you for understanding. Relations

+5
source share
1 answer

You can remove it by adding the following to the NavigationToolbar class

  actions = self.findChildren(QtGui.QAction) for a in actions: if a.text() == 'Customize': self.removeAction(a) break 

The reason you cannot remove this particular button by changing the toolitems is because it is added to the toolbar separately after adding all the toolitems entries.

  for text, tooltip_text, image_file, callback in self.toolitems: if text is None: self.addSeparator() 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) if figureoptions is not None: a = self.addAction(self._icon("qt4_editor_options.png"), 'Customize', self.edit_parameters) a.setToolTip('Edit curves line and axes parameters') 
+5
source

Source: https://habr.com/ru/post/1232633/


All Articles