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. One Shortcut for all Actions in a menu
Forum Updated to NodeBB v4.3 + New Features

One Shortcut for all Actions in a menu

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.4k 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.
  • X Offline
    X Offline
    Xv1nX
    wrote on last edited by
    #1

    Hello guys,
    i am pretty noob in Qt things and hope you can help me with my problem.

    My menu in the menubar is Camera.
    Inside i have a submenu called "Mode".
    In Mode i have 3 actions: follow main object, detached and follow specified object.
    Now i want that if the user press "C" => the camera mode will switch in a loop like : main -> detached -> specified -> main ...

    I can´t find anything like that via Google.
    Thanks in advance,
    Vince

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on last edited by
      #2

      Hi, seems a QShortcut is enough for you.

      1 Reply Last reply
      0
      • X Offline
        X Offline
        Xv1nX
        wrote on last edited by
        #3

        thanks for your answer. i will try to find out how to get it works with QShortcut.

        Edit:
        I can't find out the way, how to activate 3 actions with 1 shortcut using QShortcut. Can you pls detail the hint?

        !http://www.bilder-upload.eu/upload/9b5d94-1411723606.jpg(like this)!

        1 Reply Last reply
        0
        • X Offline
          X Offline
          Xv1nX
          wrote on last edited by
          #4

          i found the answer:
          if you want to do that you can write a protected method. looks like this:
          @void MainWindow::keyPressEvent( QKeyEvent *e )
          {
          bool consumed = false;
          switch ( e->key() )
          {
          case Qt::Key_C:
          case 0x63:
          if(followCarAct->isChecked())
          detachedCameraAct->trigger();
          else
          if(detachedCameraAct->isChecked())
          followClientAct->trigger();
          else
          followCarAct->trigger();
          consumed= true;
          break;
          }
          if(consumed)
          e->accept();
          }@

          To write the shortcut to the menu, you only have to write the code like this:
          @cameraModeMenu = cameraMenu->addMenu(tr("&Switch camera mode\tC "));@

          Source:
          http://stackoverflow.com/questions/9109952/how-to-specify-mnemonics-ampersand-shortcut-to-qactions-in-a-qmenu

          1 Reply Last reply
          0
          • X Offline
            X Offline
            Xv1nX
            wrote on last edited by
            #5

            The method above works for Linux and Windows but not for mac.
            So if anyone has an other idea, i would appreciate to read it.

            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