Key_press_event with Qt4Agg backend

I’ve been trying the Qt4Agg backend for matplotlib and I’ve encountered two problems. The following code illustrates the issues:

import matplotlib

matplotlib.use(‘Qt4Agg’)

import matplotlib.pyplot as plt

plt.ion()

plt.plot([1,2,3])

canvas=plt.gcf().canvas

def on_key(event):

print ‘you pressed’, event.key, event.xdata, event.ydata

canvas.mpl_connect(‘key_press_event’, on_key)

The problems:

  1. The user has to click within the canvas before key press events are registered. Activating the window is not sufficient.

  2. Keys ‘up’, ‘down’, ‘left’, ‘right’, ‘pageup’, and ‘pagedown’ all return event.key=None.

The tkagg and gtkagg backends don’t have these problems - key press events are active as soon as the window is active, and event.key reports the correct key. Does anyone have an idea why these problems are cropping up with Qt4 or know a workaround?

Thanks,

-Andrew Mark