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



  • 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.



  • 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



  • 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.



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



  • Adrien:

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

    Glenn



  • 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?



  • 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.



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.