[PyQt] QLineEdit vs. menu keyboard shortcuts

Nathan Weston nathan at genarts.com
Thu Jun 30 15:44:16 BST 2011

On 6/29/2011 6:16 PM, Baz Walter wrote:
> On 29/06/11 18:57, Nathan Weston wrote:
>> On 6/29/2011 1:32 PM, Baz Walter wrote:
>>> going back to your earlier example of dragging in the line-edit to
>>> change its value: all you need to do is clearFocus() when the drag
>>> starts and setFocus() when the drag ends. that way, whilst the drag is
>>> in progress, the line-edit's shortcuts won't work, but your global
>>> shortcuts will.
>>> if that's not what you want, please try to make it clear what you do
>>> want (i.e. with a working example).
> [snip]
>> Now, when the widget is in its non-editable state, and the user hits
>> Ctrl-Z, I want it to trigger the Undo action on the Edit menu.
>> Unfortunately, QLineEdit intercepts the Ctrl-Z keystroke and does
>> nothing (because it's not editable).
> the example you posted earlier works (i.e. Ctrl+Z prints 'action') if
> the Foo widget has been set as read-only.
> (nb: the setShortcutContext line also needs to be commented out)

Interesting... it works as you say on my Linux machine at home, but not 
on my Windows machine at work. The Windows machine has Qt 4.6.2, I don't 
know about the Linux machine off the top of my head. What platform/Qt 
version are you testing on?

>> I can't call clearFocus() at the end of the drag, because this would
>> break the Up/Down arrow shortcuts.
> call clearFocus() at the *start* of the drag, setFocus() at the *end*.

I don't see how that would help... after the drag, the line-edit will 
have focus again, and will eat the Ctrl-Z shortcut.

. . . . . . . . . . . . . . . . . . . . . . . . .
Nathan Weston                   nathan at genarts.com
GenArts, Inc.                   Tel: 617-492-2888
955 Mass. Ave                   Fax: 617-492-2852
Cambridge, MA 02139 USA         www.genarts.com

More information about the PyQt mailing list