Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How get lower-case menu shortcut?
buckler last edited by
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:
I just want a lower case c.
I don't believe it's possible. What would be the difference between lowercase and uppercase letter anyway ...?
buckler last edited by
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?
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
QMenuBar). Maybe I'm wrong, and maybe someone will suggest something better
, but don't hold your breath.
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.
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.
KeithS last edited by
Am I missing something?
setShortcut(tr("C")); // sets shortcut to lower case C
setShortCut(tr("Shift+C")); // sets shortcut to uppercase C
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.