[PyQt] QLineEdit vs. menu keyboard shortcuts

Nathan Weston nathan at genarts.com
Tue Jun 28 18:56:35 BST 2011


On 6/28/2011 1:48 PM, Baz Walter wrote:
> On 28/06/11 16:50, Nathan Weston wrote:
>> QLineEdit has some keyboard shortcuts (e.g. Ctrl+Z for Undo) that clash
>> with the shortcuts for QActions in my application menus. When a
>> QLineEdit has keyboard focus, it intercepts these shortcuts and my
>> QActions are never triggered.
>>
>> I'd like to give application-level shortcuts precedence over QLineEdit's
>> shortcuts, but I can't seem to find a clean and general way to do this.
>>
>> Alternatively, is there a way to customize the keyboard shortcuts in
>> QLineEdit? If I could disable some of the problematic shortcuts that
>> would be a reasonable workaround.
>
> the default key bindings for QLineEdit are hard-coded, but the actual
> key sequences used are platform-dependent (and the same goes for most
> (all?) other widgets which have them).
>
> but what is your reason for wanting to change the default behaviour?
>
> as a user, i would expect all the 'normal' shortcuts to work when typing
> in a line edit. if Ctrl+Z undid something in some other widget that i
> wasn't looking at, it could become very confusing. (IIRC this was how
> things used to work with qt3 - and good riddance to that!).

I have a subclass of QLineEdit for entering numbers. The user can either 
type in a number, or drag the mouse to increase/decrease the value, like 
a slider (similar widgets are often found in After Effects and other 
video editing software).

In the latter mode, the widget is temporarily set as non-editable, so 
its built-in Undo behavior doesn't work at all (but it still eats the 
keyboard event!).

-- 
. . . . . . . . . . . . . . . . . . . . . . . . .
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