I'm embedding a matplotlib figure in PyQt4 UI. Something like
Building a matplotlib GUI with Qt Designer.
FigureCanvasQTAgg and NavigationToolbar2QT are added in QVBoxlayout and right side of UI is a QListWidget of figure names.
None of the toolbar shortcuts are working. I tried changing focus of the both QVBoxlayout and QListWidget Widget.
Figure is generated as
from matplotlib.figure import Figure
fig=figure()
ax=fig.add_subplot(111)
ax.plot.plot(np.random.rand(5))
This figure is passed to addmpl method where canvas and toolbar are generated and added to the mainwindow widget.
def addmpl(self,fig):
self.canvas = FigureCanvas(fig)
self.mplvl.addWidget(self.canvas)
self.canvas.draw()
self.toolbar = NavigationToolbar(self.canvas,self.mplwindow)
self.mplvl.addWidget(self.toolbar)
Workaround...
def menu(self):
self.savefig=QtGui.QAction('&Save', self)
self.savefig.setShortcut('Ctrl+S')
self.savefig.triggered.connect(self.save_figure)
undo=QtGui.QAction('&Undo', self)
undo.setShortcut('Ctrl+Z')
undo.triggered.connect(self.back)
redo=QtGui.QAction('&Redo', self)
redo.setShortcut('Ctrl+Y')
redo.triggered.connect(self.forward)
figoptions=QtGui.QAction('&Figure Options', self)
figoptions.setShortcut('Ctrl+F')
figoptions.setStatusTip('Edit curves lines and axes parameters')
figoptions.triggered.connect(self.edit_parameters)
def back(self):
self.toolbar.back()
def forward(self):
self.toolbar.forward()
def save_figure(self):
self.toolbar.save_figure()
def edit_parameters(self):
self.toolbar.edit_parameters()
But the shortcuts like Constrain pan/zoom to x axis - hold x when panning/zooming with mouse looks difficult and tedious to implement.
Solution of this Question has the same problem.(Replaced NavigationToolbar2QTAgg with NavigationToolbar2QT)