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?
def __init__(self):
super().__init__()
self.
act = QtGui.
QAction('test', self
) self.act.setShortcutContext(Qt.WidgetWithChildrenShortcut)
self.addAction(self.act)
self.act.triggered.connect(self.slot)
def slot(self):
print('triggered')
class Widget(QtGui.QWidget):
def __init__(self):
super().__init__()
self.act = QtGui.QAction('test', self)
self.act.setShortcut(QtGui.QKeySequence(QtGui.QKeySequence.Copy))
self.act.setShortcutContext(Qt.WidgetWithChildrenShortcut)
self.addAction(self.act)
self.act.triggered.connect(self.slot)
def slot(self):
print('triggered')
To copy to clipboard, switch view to plain text mode
Bookmarks