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. QKeySequence - multiple keys
Forum Updated to NodeBB v4.3 + New Features

QKeySequence - multiple keys

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.5k 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.
  • B Offline
    B Offline
    bhatiaharsh
    wrote on last edited by
    #1

    I am trying to create shortcuts for menu actions, which include multiple keys. For the actions directly in the menu list, I am using shortcuts like "Ctrl + 1", etc. which works just fine.

    @QAction *qa_enableLighting = viewer_menu->addAction("Enable Lighting", this, SLOT(on_action_enableLighting_triggered()), QKeySequence(Qt::CTRL + Qt::Key_1));@

    However, for an action under a sub-menu, I would like to use multiple keys, for example, "Ctrl + V + 1". When I try to create this keysequence, it does not work, i.e. the shortcut just doesn't show up.

    @QAction *qa_submenu = submenu->addAction("Test 1", this, SLOT(on_action_submenu1_triggered()), QKeySequence(Qt::CTRL + Qt::Key_V + Qt::Key_1));@

    Instead, when I used
    @QKeySequence(Qt::CTRL + Qt::Key_M + Qt::Key_1))@

    the shortcut showed up as "Ctrl+~". I understand that Ctrl+V is a standard shortcut, and probably that is why Qt is not allowing me to use it, while "M+1" is creating "~". However, is there a way to enable using sequences of the following form ?

    @Ctrl + <key_of_my_choice> + 1@

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You can't do it like that. QKeySequence's documentation explains why: a shortcut is composed of one Qt::Key and 0 or more modifiers.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bhatiaharsh
        wrote on last edited by
        #3

        Thanks for the pointer, SGaist. But is there an easy way to use multiple keys ?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I would say an event filter where you keep track of the keys pressed and act accordingly

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

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