[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Can't get keyboard shortcuts to work
From:       David Townshend <aquavitae69 () gmail ! com>
Date:       2012-01-22 20:04:19
Message-ID: CAEgL-fdOs9b=GP3nyMA96hS2+2GLgXYknJgGcs8+QkBt6ZUzzA () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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@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@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>

[Attachment #5 (text/html)]

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&#39;ve got quite a bit of \
abstraction around the QActions and I somehow missed it!<br>

<br><div class="gmail_quote">On Sun, Jan 22, 2012 at 2:16 PM, Hans-Peter Jansen <span \
dir="ltr">&lt;<a href="mailto:hpj@urpla.net">hpj@urpla.net</a>&gt;</span> \
wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px \
#ccc solid;padding-left:1ex">

<div class="HOEnZb"><div class="h5">On Thursday 19 January 2012, 10:53:31 David \
Townshend wrote:<br> &gt; I can&#39;t get keyboard shortcuts to work with \
Qt.WidgetShortcut<br> &gt; or Qt.WidgetWithChildrenShortcut context.  It seems that \
nothing I do<br> &gt; will trigger the action. Below is a sample class which is \
giving the<br> &gt; problem. Can anyone point out where I am going wrong?<br>
&gt;<br>
&gt; class Widget(QtGui.QWidget):<br>
&gt;     def __init__(self):<br>
&gt;         super().__init__()<br>
&gt;         self.act = QtGui.QAction(&#39;test&#39;, self)<br>
&gt;<br>
&gt; self.act.setShortcut(QtGui.QKeySequence(QtGui.QKeySequence.Copy))<br>
&gt; self.act.setShortcutContext(Qt.WidgetWithChildrenShortcut)<br>
&gt; self.addAction(self.act)<br>
&gt;         self.act.triggered.connect(self.slot)<br>
&gt;<br>
&gt;     def slot(self):<br>
&gt;         print(&#39;triggered&#39;)<br>
<br>
</div></div>Check out FocusPolicy in the fine manual..<br>
<br>
Pete<br>
<br>
<br>
_______________________________________________<br>
PyQt mailing list    <a \
href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><br> <a \
href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt" \
target="_blank">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br> \
</blockquote></div><br>



_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic