Results 1 to 8 of 8

Thread: Cannot override copy shortcut

  1. #1
    Join Date
    Jul 2008
    Posts
    31
    Thanks
    1
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Cannot override copy shortcut

    Dear all,

    I have a custom context menu that acts on a table view.
    There is a copy action in the menu.
    It has a shortcut set via designer to be Ctrl+C.
    When I use the Ctrl+C key combination the corresponding action is not triggered.
    Instead the default copy-a-single-cell behaviour is executed.

    What do I have to do to have a shortcut of an action invoke the action?

    Are there any issues in overriding standard shortcuts such as copy (Ctrl+C)?

    Kind Regards,

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Cannot override copy shortcut

    The action has to be "visible" for its shortcut to be active. You need to add it to some menu or button or make the action active in global context.

  3. #3
    Join Date
    Jul 2008
    Posts
    31
    Thanks
    1
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Cannot override copy shortcut

    The actions are part of context menus generated at runtime. I guess this is not enough then?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Cannot override copy shortcut

    No, that's not enough. You can press Ctrl+C when the context menu is visible and the action should work then but not when the menu is hidden.

    You can try adding the action directly to the widget using QWidget::addAction(), maybe it will be sufficient.

  5. #5
    Join Date
    Jul 2008
    Posts
    31
    Thanks
    1
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Cannot override copy shortcut

    That's very disappointing. So if I had a custom spreadsheet application I can only copy a range with Ctrl+C when the action is visible?

    I wonder how the default copy shortcut works...

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Cannot override copy shortcut

    Quote Originally Posted by Paladin12 View Post
    That's very disappointing. So if I had a custom spreadsheet application I can only copy a range with Ctrl+C when the action is visible?
    How else would a user know there is an action with a Ctrl+C shortcut?

    I wonder how the default copy shortcut works...
    I don't know what you mean by "default copy shortcut" but you can install an application wide shortcut if you want. Not directly through QAction though.

  7. #7
    Join Date
    Jul 2008
    Posts
    31
    Thanks
    1
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Cannot override copy shortcut

    I see now. I'm trying to implement many Ctrl+C's that behave differently depending upon the widget they are acting upon, and Qt does not support this.

    I need something like a contextual shortcut, but they don't exist.

    Thanks for your help anyway!

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Cannot override copy shortcut

    Quote Originally Posted by Paladin12 View Post
    I see now. I'm trying to implement many Ctrl+C's that behave differently depending upon the widget they are acting upon, and Qt does not support this.
    Why not?

    I need something like a contextual shortcut, but they don't exist.
    Every shortcut in Qt has a context. See the docs for QShortcut.

Similar Threads

  1. How to override system shortcut left Alt+Space
    By MasterBLB in forum Qt Programming
    Replies: 2
    Last Post: 28th March 2010, 11:28
  2. override shortcut icon in QToolBar
    By sudhansu in forum Qt Programming
    Replies: 1
    Last Post: 18th February 2010, 08:20
  3. Override a signal
    By daviddoria in forum Newbie
    Replies: 4
    Last Post: 9th February 2010, 18:18
  4. override wheelEvent for QScrollBar
    By ChasW in forum Qt Programming
    Replies: 6
    Last Post: 25th January 2007, 09:50
  5. override minimumSize function
    By niko in forum Qt Programming
    Replies: 4
    Last Post: 30th October 2006, 05:28

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.