[PyQt] Can't get keyboard shortcuts to work

David Townshend aquavitae69 at gmail.com
Sun Jan 22 20:04:19 GMT 2012


Thanks for the reply.  I just realised that the example I sent does
actually work (once I sort out the focus).  After about an hour of testing
I discovered that in my actual scenario I never called widget.addAction().
 I've got quite a bit of abstraction around the QActions and I somehow
missed it!

On Sun, Jan 22, 2012 at 2:16 PM, Hans-Peter Jansen <hpj at urpla.net> wrote:

> On Thursday 19 January 2012, 10:53:31 David Townshend wrote:
> > 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')
>
> Check out FocusPolicy in the fine manual..
>
> Pete
>
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20120122/de9b4f7f/attachment.html>


More information about the PyQt mailing list