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

Jaco Naude naude.jaco at gmail.com
Wed Feb 9 10:40:03 CET 2011


I meant the action's shortcut context:
http://doc.qt.nokia.com/latest/qaction.html#shortcutContext-prop

<http://doc.qt.nokia.com/latest/qaction.html#shortcutContext-prop>I agree
with you that it should work they way you did it if your actions' shortcut
context are all set to Qt::ApplicationShortcut.



On Wed, Feb 9, 2011 at 9:16 AM, Wilhelm <wilhelm.meier at fh-kl.de> wrote:

> Am 09.02.2011 10:10, schrieb Jaco Naude:
> > Are you setting the action's context to be application wide?
>
> What do you mean: I'm not aware of an action context, I only know
> shortcut context ...
>
> >
> > On Wed, Feb 9, 2011 at 8:31 AM, Wilhelm <wilhelm.meier at fh-kl.de
> > <mailto:wilhelm.meier at fh-kl.de>> wrote:
> >
> >     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>
> >     > <mailto: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>
> >     <mailto:Qt-interest at qt.nokia.com <mailto:Qt-interest at qt.nokia.com>>
> >     >     http://lists.qt.nokia.com/mailman/listinfo/qt-interest
> >     >
> >     >
> >
> >
> >     --
> >     Wilhelm
> >
> >
>
>
> --
> Wilhelm
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110209/33f08063/attachment.html 


More information about the Qt-interest-old mailing list