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.
-
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?
-
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?
@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
andQMenuBar
). 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 acceptsQString
. See the answers below. -
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. -
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.
-
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.