Using PyQt4, I can't get keyboard shortcuts to work with the Qt.WidgetShortcut or Qt.WidgetWithChildrenShortcut contexts (nothing happens when I press the shortcut). I'm pretty sure its something simple I'm missing, but I just can't figure out what. Here is a sample class showing the steps I'm using. Can anyone point out what I'm missing?

Qt Code:
  1. class Widget(QtGui.QWidget):
  2. def __init__(self):
  3. super().__init__()
  4. self.act = QtGui.QAction('test', self)
  5. self.act.setShortcut(QtGui.QKeySequence(QtGui.QKeySequence.Copy))
  6. self.act.setShortcutContext(Qt.WidgetWithChildrenShortcut)
  7. self.addAction(self.act)
  8. self.act.triggered.connect(self.slot)
  9.  
  10. def slot(self):
  11. print('triggered')
To copy to clipboard, switch view to plain text mode