Results 1 to 7 of 7

Thread: Same shortcut for different actions in different widgets

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Same shortcut for different actions in different widgets

    Quote Originally Posted by totem View Post
    I guess QSignalMapper would do the trick, but I never really got how it works.. nor I spent time trying to get it.
    Take a look at Qt MDI example, it's used here
    Ok, having had a look at it, I don't think this is what I am after. It seems to me that QSignalMapper is used in the MDI example to get the MDI child windows activated. Also with regards to the 'shared' actions, I want to be able to have different tooltips, etc. and I can't see how QSignalMapper can address that.

    Quote Originally Posted by nightghost View Post
    See Qt::ShortcutContext for this and add the actions to the correct widgets!
    I tried that earlier, but maybe didn't do it right. Will try again...

    Quote Originally Posted by Zlatomir View Post
    My opinion is that you should re-think the keyboard shortcuts and note that for many of us (and likely many of your users) Ctrl+C means copy.

    And put your self in the "user" perspective, would you like to use an application which uses Ctrl+C all over the place and each time you press the key combination does a different thing depending on which widget has focus?
    You clearly haven't read my message. Try again.
    Last edited by agarny; 30th March 2011 at 17:27.

  2. #2
    Join Date
    May 2010
    Posts
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11
    Wiki edits
    11

    Default Re: Same shortcut for different actions in different widgets

    In the application I've implemented there is a case where a QAction associated with a widget has the same shortcut as a different QAction associated with a menu item for the same user effect. The reason for this is irrelevant (has to do with needing distinct slots handling the QAction triggered signals in the different contexts). To avoid the ambiguous shortcut problem I employ setShortcutContext(Qt::WidgetWithChildrenShorcut) applied to the QAction used in the more restrictive context. This enables the "lower level" widget to which the restricted QAction has been applied to consume the shortcut key event and prevent it from "bubbling up" to the menu item with the other QAction that has the same shortcut, yet still allows shortcut key events generated "above" the lower level widget to reach the "higher level" menu item's QAction.

Similar Threads

  1. Can i add Actions to QDockWidget
    By ladiesfinger in forum Qt Programming
    Replies: 4
    Last Post: 30th January 2011, 15:11
  2. help with QSignalMapper and actions
    By andreime in forum Newbie
    Replies: 1
    Last Post: 9th August 2009, 18:24
  3. Replies: 2
    Last Post: 31st July 2009, 09:18
  4. Spacing widgets and actions in a toolbar
    By indifference in forum Qt Programming
    Replies: 1
    Last Post: 5th September 2007, 22:59
  5. Actions and what to do with them?
    By krsmichael in forum Qt Tools
    Replies: 2
    Last Post: 20th January 2006, 22:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.