Issue
This is my first question of stackoverflow! I've got a PyQT gui that's displaying an mpl figure canvas. I've set the margins around my main axes to 0 so the plot will completely fill the figure canvas and the widget that contains it. The problem is that when I do this I no longer get the axes_leave_event
when I leave the figure canvas. For example when I've clicked on the pan button in the mpl_toolbar
my cursor changes to the cross-arrows but when I leave the widget I'd like it to return to normal and return to the cross-arrows when I reenter the widget. If I don't minimize my margins around the axes then it works like I would like. I can also connect the axes_leave_event
but I don't want to connect it I want to emit it and can't figure out how to do that.
Thanks so much all.
My application is fairly large so I'll just show the code that I think is most relevent.
def create_main_frame(self):
self.dpi = 100
self.fig = Figure((5.0, 4.0), dpi=self.dpi)
self.fig.subplots_adjust(left = 0, right=1, top=1, bottom=0)
self.map_canvas = MyDiagram(self.fig)
self.add_axis()
self.mpl_toolbar = NavigationToolbar(self.map_canvas, None)
self.layout().addWidget(self.map_canvas)
class MyDiagram(FigureCanvas):
def __init__(self, fig):
FigureCanvas.__init__(self, fig)
self.mpl_connect('axes_leave_event', self.testing)
def resizeEvent(self, event):
if not event.size().height() == 0:
FigureCanvas.resizeEvent(self, event)
def testing(self, event):
pass
def leaveEvent(self, event):
FigureCanvas.leaveEvent(self, event)
#If I could somehow get the 'axes_leave_event' to fire right here I would be set.
Solution
This is somewhat based on guesswork, since I can't test it with matplotlib
, but something along these lines might work:
class MyDiagram(FigureCanvas):
def __init__(self, fig):
FigureCanvas.__init__(self, fig)
self._cursor = None
def enterEvent(self, event):
if (self._cursor is not None and
QApplication.overrideCursor() is None):
QApplication.setOverrideCursor(self._cursor)
FigureCanvas.enterEvent(self, event)
def leaveEvent(self, event):
self._cursor = QCursor(QApplication.overrideCursor())
QApplication.restoreOverrideCursor()
FigureCanvas.leaveEvent(self, event)
Answered By - ekhumoro
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.