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

Jaco Naude naude.jaco at gmail.com
Wed Feb 9 06:35:00 CET 2011


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.

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> 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
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110209/3712c7ca/attachment.html 


More information about the Qt-interest-old mailing list