Important: Please read the Qt Code of Conduct -

Does shortcut context Qt::WidgetShortcut action in menu disable shortcut?

  • Hi.

    I just found myself in a situation similar to the one described in - that is, I wanted to display shortcut info in a menu entry without getting the actual shortcut behaviour, because the shortcut is already handled via a "global" QShortcut. I found a new (possible) solution to the problem, though - I did

    QAction *action=menu->addAction("MyAction");
    QKeySequence shortcut=...;

    and found that the action would never be activated by the shortcut (even if disabling the "global" shortcut.)


    • Why exactly is the shortcut (seemingly) inactive in all states when set up this way? It seems like it ought to be when the menu isn't visible, but how about the rather special case when you open the menu, then press the shortcut sequence?
    • Will this work the same way on all systems? Can it be considered as a reliable way to "disable" a menu entry shortcut?

    This solution does seem like bit of a hack in some respects, but less so (I think) than inserting the shortcut text "by hand", and it's a lot easier than messing around with event filters...

    • Toralf

Log in to reply