[PyQt] Can't get keyboard shortcuts to work

David Townshend aquavitae69 at gmail.com
Thu Jan 19 09:53:31 GMT 2012


I can't get keyboard shortcuts to work with Qt.WidgetShortcut
or Qt.WidgetWithChildrenShortcut context.  It seems that nothing I do will
trigger the action. Below is a sample class which is giving the problem.
 Can anyone point out where I am going wrong?

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')

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20120119/1211a5d5/attachment.html>


More information about the PyQt mailing list