How get lower-case menu shortcut?



  • Hello,
    I have been trying to get a lower-case menu shortcut key. I cannot see how to do it, it always comes out upper case. Here is my simple line of code:
    ToggleCoronalAction->setShortcut(Qt::Key_C|Qt::NoModifier);

    I just want a lower case c.


  • Qt Champions 2016

    @buckler
    I don't believe it's possible. What would be the difference between lowercase and uppercase letter anyway ...?



  • I think most people assume that when they press the key without a shift, it is the lower case, and to get the upper case, they would also press the shift. So part of it is trying to accord with user sense of what the key press is. But in addition to that, the purpose of the modifiers, not only shift but ctrl, alt, etc., is to expand the effective number of keys.

    This may allow re-formulation of my question. Is what I have coded correct, insofar as triggering on c without shift, but that the display reading as capital C doesn't reflect it correctly? in which case, then the question is how to get the shortcut to display correctly, i.e., to show 'c' instead of 'C' in this example?


  • Qt Champions 2016

    @buckler said:

    Is what I have coded correct, insofar as triggering on c without shift, but that the display reading as capital C doesn't reflect it correctly?

    I'd say yes. Still, having shortcuts bound to keys without modifiers is somewhat unusual.

    in which case, then the question is how to get the shortcut to display correctly, i.e., to show 'c' instead of 'C' in this example?

    As I said, I don't think it's possible through standard means (the only way I could fathom would be to have your own implementation of QMenu and QMenuBar). Maybe I'm wrong, and maybe someone will suggest something better , but don't hold your breath.

    EDIT:
    Well, now I look like an idiot. I completely forgot that there's implicit constructor for the key sequence that accepts QString. See the answers below.


  • Qt Champions 2016

    Hi
    While it will work to use "c" as shortcut for say an action in qtoolbar
    if you then place a textEdit on the form too, the shortcut will stop working
    if textedit has focus. At least my test did.

    Whereas if u use alt+c, it still works even if keyboard focus is on other widget.

    My guess is that using shortcut keys for toolbar or menu will have issues unless
    an modifier is used.



  • @buckler

    Am I missing something?

    setShortcut(tr("C")); // sets shortcut to lower case C
    setShortCut(tr("Shift+C")); // sets shortcut to uppercase C


  • Lifetime Qt Champion

    Hi,

    AFAIK, It's a bit simpler than that:

    setShortcut(tr("C")); // sets shortcut to key C
    setShortCut(tr("Shift+C")); // sets shortcut to key C with Shift modifier
    

    There's no notion of casing.


Log in to reply
 

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