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

Wilhelm wilhelm.meier at fh-kl.de
Wed Feb 9 09:31:15 CET 2011


Hi Jaco,

Am 09.02.2011 06:35, schrieb Jaco Naude:
> Hi Wilhelm
> 
> One way to solve the problem is to have a front-end action with multiple
> backend actions. The active backend action will then depend on the
> widget that has focus and you connect the triggered() signal of the
> frontend action to the triggered() signal on the backend action etc. 

Yes, that was my first idea: to have a say ProxyAction for all those
actions. But I thought there must be al solution in Qt allready.

Then I came across the shortcutContext property of QAction and tried to
set the contexts of all the "overlapping" actions to Qt::WidgetShortcut
instead of the default Qt::WindowShortcut. But I noticed no change !?!

The description of Qt::WidgetShortcut says:
The shortcut is active when its parent widget has focus.

So if I install an action on a QWidget I would assume that the actions
shortcut is only active if the QWidget has focus, right? But this seems
to be broken somehow. Or do I misinterpret something?

> 
> Look at the screenshot below which shows what I mean:
> http://www.qtilities.org/images/screenshots/conan_screenshot2.jpg
> 
> The "Expand All" action exists at multiple places (10 in this case)
> where I have tree views. The one that has focus must be the active
> backend action, in this case it is a widget called
> "Qtilities.Core.ObjectPool". Note that it shows it is active and the the
> connection analyzer shows us that the triggered() signals are connected
> correctly.
> 
> To activate your action will depend on your implementation. In my case I
> use contexts with IDs to define what the active context is. For example
> if I want to activate the action in the QEvent::FocusIn of my widget I
> install an event filter on the view and do something like this:
> 
> bool MyWidget::eventFilter(QObject *object, QEvent *event) {      
>   if (object == d->tree_view && event->type() == QEvent::FocusIn) {
>       CONTEXT_MANAGER->setNewContext(contextString(),true);
>       return false;
>   }
> }        
> 
> See http://www.qtilities.org/docs_master/page_action_management.html for
> more details.
> 
> Hope this helps,
> Cheers
> Jaco
> 
> 
> On Tue, Feb 8, 2011 at 9:06 PM, Wilhelm <wilhelm.meier at fh-kl.de
> <mailto:wilhelm.meier at fh-kl.de>> wrote:
> 
>     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?
> 
>     --
>     Wilhelm
> 
>     _______________________________________________
>     Qt-interest mailing list
>     Qt-interest at qt.nokia.com <mailto:Qt-interest at qt.nokia.com>
>     http://lists.qt.nokia.com/mailman/listinfo/qt-interest
> 
> 


-- 
Wilhelm




More information about the Qt-interest-old mailing list