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. Single key QAction shortcuts don't work on Mac OS X (Qt 5.x)
Forum Updated to NodeBB v4.3 + New Features

Single key QAction shortcuts don't work on Mac OS X (Qt 5.x)

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 5.1k 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.
  • G Offline
    G Offline
    gkroeger
    wrote on last edited by
    #1

    Before I file a bug report (and one already exists) I wanted to poll to see if anyone else has worked on this issue or knows of an explanation or workaround.

    Seems that single key shortcuts for QAction are broken on Mac OS X for all Qt5.x versions.

    This shows up first when the delete key doesn't fire a QAction its assigned to. This was reported as a bug with delete and backspace keys (QTBUG-33015).

    I have been experimenting, and found that the problem is more precisely stated that any single key shortcut doesn't work. Replacing working command-key pairs with single keys breaks… and replacing delete with command-delete works. I have also tested and verified that the problem is not in the translation code… i.e. the problem is there even with an explicit action->setShortcut(Qt::Key_X)

    What puzzles me is that delete key works fine in textEdit widgets… perhaps they don't use a QAction?

    By the way, things are fine in Qt4.8.5. Things are also fine on Windows with Qt5.2, so the problem seems confined to Mac OS X and direct use of QActions.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Adrien Leravat
      wrote on last edited by
      #2

      Hi gkroeger,

      In text edit, keyboard events are used directly. And actually this is something you can also do to handle those keys yourself: you can create an even filter that you add on the QApplication, and test event type for Keyboard event.

      If it matches, you can do whatever you want, and discard the event, to avoid further processing.

      See the following link to install an event filter: "http://qt-project.org/doc/qt-5/qobject.html#installEventFilter":http://qt-project.org/doc/qt-5/qobject.html#installEventFilter

      Regards

      Adeneo Embedded - www.adeneo-embedded.com

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gkroeger
        wrote on last edited by
        #3

        Adrien:

        Thanks for the suggestion… I will try to craft a work-around… but it still seems like a significant bug in 5.x since it works fine on 4.x and 5.x on all platforms except Mac OS X.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Adrien Leravat
          wrote on last edited by
          #4

          Sure it is. Have you tried 5.2 ? A duplicate/similar bug may have been solved in this latest release.

          Adeneo Embedded - www.adeneo-embedded.com

          1 Reply Last reply
          0
          • G Offline
            G Offline
            gkroeger
            wrote on last edited by
            #5

            Adrien:

            I have, and it is still broken in both 5.2RC and 5.2 release.

            Glenn

            1 Reply Last reply
            0
            • G Offline
              G Offline
              gkroeger
              wrote on last edited by
              #6

              I am bumping this back up as the problem is still showing in 5.2.1!

              Is this supposed to be a feature? I am stunned that there has been no activity at all on the bug report.

              Is there some other way to implement a delete action using the delete key?

              1 Reply Last reply
              0
              • hskoglundH Offline
                hskoglundH Offline
                hskoglund
                wrote on last edited by
                #7

                Hi, I just tried that qt5delete program as well, the closest I could get was using a simple 0x7F for the delete key, e.g.:
                action->setShortcut(0x7F);

                This works if you have an external Mac keyboard with that other Delete key (to the right of the \ key), but on the normal keyboard you have to type fn+delete. So as you say, the normal Delete key is not possible to map with setShortcut();

                The bug/feature seems to be in qcocoahelpers.mm in the lookup table, where both the NSBackspaceCharacter and NSDeleteCharacter are mapped to the same Qt::Key_Backspace :-(

                =================
                EDIT: BTW, single key shortcuts do work on the Mac, for example:
                backspaceAct->setShortcut(QKeySequence(Qt::Key_F1));

                Normal letters and numbers do not work, I think that's a feature of the menu system.

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  gkroeger
                  wrote on last edited by
                  #8

                  hskogland:

                  Thanks for the suggestions. Some more playing around has produced the following two observations:

                  1. The problem can be fixed by giving the delete action an icon and inserting it into a menubar. I know that this has been an issue with some actions before, but in this case the action already had a widget as a parent, and worked when some two character codes were assigned, e.g. command-L.

                  2. Taking the same source code back to 4.8.5 restores the "normal" behavior, i.e. the single key works and no icon in a toolbar is required.

                  So the problem is going to need some more diagnosis… which I will attempt.

                  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