Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to activate QActions from keypresses?

How to activate QActions from keypresses?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 425 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kitfox
    wrote on last edited by kitfox
    #1

    Does Qt have an API feature for activating QActions when certain keys are pressed, or does each widget need to do this independently via the keyPressEvent()? I know that Java's Swing API has a keymap feature that handles this and was wondering if Qt had something similar.

    In other words - what's the recommended way to have something like Ctrl-V activate a Paste action?

    JonBJ 1 Reply Last reply
    0
    • K kitfox

      Does Qt have an API feature for activating QActions when certain keys are pressed, or does each widget need to do this independently via the keyPressEvent()? I know that Java's Swing API has a keymap feature that handles this and was wondering if Qt had something similar.

      In other words - what's the recommended way to have something like Ctrl-V activate a Paste action?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @kitfox
      QActions can have "shortcut keys" associated with them. See http://doc.qt.io/qt-5/qaction.html#shortcut-prop. So the action holds what key activates it for you.

      1 Reply Last reply
      4
      • ValentinMicheletV Offline
        ValentinMicheletV Offline
        ValentinMichelet
        wrote on last edited by
        #3

        To complete JonB’s answer, you have several ways to specify a shortcut for an action:

        action->setShortcut(QKeySequence::Copy);
        action->setShortcut(QKeySequence(Qt::CTRL+Qt::key_v));
        action->setShortcut(QKeySequence("CTRL+V");
        
        1 Reply Last reply
        3

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved