[Qt-interest] How install shortcuts for multiple widgets?

Espen Sture Arnesen espen.sture.arnesen at pgs.com
Wed Feb 9 12:43:11 CET 2011


On Wed, 09 Feb 2011 11:11:08 +0100, Frederic Tingaud <tingaud at gostai.com>  
wrote:

>   Le 08/02/2011 22:06, Wilhelm a écrit :
>> Hi all,
>>
>> what is the "right" way to install shortcuts (say Ctrl-S) without
>> getting the "... ambiguous shortcut ..." error?
>>
>> If I have an application menu with an action using shortcut Ctrl-S and
>> e.g. several other widgets which also install this shortcut I get the
>> above error.
>>
>> So the question is, how to setup up an applications-wide shortcut Ctrl-S
>> that saves a file A if triggered in a texteditor widget A if that has
>> focus, or saves a file B if triggered in a texteditor widget B if that
>> has focus?
>>
>> I tried using the shortcut-context and setting it to WidgetContext but
>> without luck.
>>
>> Any hints?
>>
>
> I had the same question and after looking at existing code and
> struggling without success with shortcuts context, I decided to stop
> using shortcuts for these kind of cases and using QKeyEvent on the
> different widgets. I lose the display of shortcuts in menus, but apart
> from this, it works perfectly well.

Personally, I use a Singleton-class that creates and holds a pointer to  
QActions for these application-wide actions and implement the code for it  
in a central main class. This works for me as long as the shortcut should  
do the same in all instances.

In short, the QAction is one instance that does one thing and I access the  
same QAction from several widgets.

Espen

This e-mail, including any attachments and response string, may contain proprietary information which is confidential and may be legally privileged. It is for the intended recipient only. If you are not the intended recipient or transmission error has misdirected this e-mail, please notify the author by return e-mail and delete this message and any attachment immediately. If you are not the intended recipient you must not use, disclose, distribute, forward, copy, print or rely on this e-mail in any way except as permitted by the author.



More information about the Qt-interest-old mailing list