Skip to content


Fix Qt canvas resize_event #1585

merged 1 commit into from

4 participants


The Qt backend doesn't fire resize_event when resizing so callbacks connected to the event never get called. The following example should print when the figure is resized:

import matplotlib as mpl
import matplotlib.pyplot as plt

def printer(event):

fig = plt.figure()
fig.canvas.mpl_connect('resize_event', printer)

This PR just adds a call to resize_event. (Some slight refactoring also wandered into the commit.)

Matplotlib Developers member

:+1: good work @tonysyu.

Matplotlib Developers member

Merging (and backporting to v1.2.x)

@mdboom mdboom merged commit 80a406c into matplotlib:master

1 check passed

Details default The Travis build passed
Matplotlib Developers member

This was cherry-picked as f6fcb39

(tracked it down, might as well record it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 11, 2012
  1. @tonysyu
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 3 deletions.
  1. +5 −3 lib/matplotlib/backends/
8 lib/matplotlib/backends/
@@ -289,15 +289,17 @@ def keyReleaseEvent( self, event ):
FigureCanvasBase.key_release_event( self, key )
if DEBUG: print('key release', key)
- def resizeEvent( self, event ):
- if DEBUG: print('resize (%d x %d)' % (event.size().width(), event.size().height()))
+ def resizeEvent(self, event):
w = event.size().width()
h = event.size().height()
- if DEBUG: print("FigureCanvasQtAgg.resizeEvent(", w, ",", h, ")")
+ if DEBUG:
+ print('resize (%d x %d)' % (w, h))
+ print("FigureCanvasQt.resizeEvent(%d, %d)" % (w, h))
dpival = self.figure.dpi
winch = w/dpival
hinch = h/dpival
self.figure.set_size_inches( winch, hinch )
+ FigureCanvasBase.resize_event(self)
QtGui.QWidget.resizeEvent(self, event)
Something went wrong with that request. Please try again.