The M is silent. In computing this stands for the underlined letters in menus that can be triggered using an Alt+Letter key combination, one that you can remember and apply later to navigate around more quickly.

Qt and other toolkits typically use an ampersand to denote a mnemonic when assigning a menu entry. For instance, “&Shutdown” will be displayed as “Shutdown” and trigger on Alt+S whereas “Slee&p” will be “Sleep” and trigger on Alt+P. Of course this isn’t limited to menus, pretty much any control, buttons and what not, can have mnemonics. Since they are part of the label, a translated string can and likely will have a different one.
KDE applications, both written in Qt Widgets and Qt Quick, automatically assign mnemonics for most controls that don’t have one explicitly set. This is done through KAcceleratorManager and Kirigami’s MnemonicData, respectively, using a set of rules based on the control’s type. For example, a toolbar button is less important than a regular button or check box but both are more important than a section label. It also tries to use the first letter of a word, if that letter is not already taken. If a control is hidden the shortcut is removed again. The end result in a German dialog is “&Abbrechen” (Cancel), “&OK”, and “A&nwenden“ (Apply, since the A was already taken) for its footer.
While our Qt Quick Controls 2 Desktop Style automatically assigned mnemonics for all of its controls, Plasma Components did not for CheckBoxes, Switches, and some others. That is now fixed and it’s now possible to use e.g. Alt+R to Raise maximum volume in the Volume applet or switch to the Applications tab using Alt+A. Likewise for the circular action button used on the lock and logout screens, you can now Alt+P to Sleep from the logout and lock screens! The “S” is taken for shutdown for consistency and unused on the lock screen.

I noticed that I couldn’t trigger the toolbar buttons in System Settings even though they clearly showed an underlined letter. Turns out the shortcut was registered twice for some reason! If this happens, neither action is executed and instead the “activated ambiguously” signal is emitted. Kirigami’s ActionToolBar is effectively two views: the regular strip of buttons and an overflow menu. The buttons are shown dynamically based on how much room there is available and the action’s priority. There was a bug in Kirigami’s mnemonic handler where hiding a control wouldn’t release its shortcut, effectively registering every toolbar shortcut twice.
Speaking of Kirigami, there’s a FormLayout similar to QFormLayout that we use for most of our settings pages. It has a label on the left, and control on the right. By default, the label generates a mnemonic to focus its buddy. However, we don’t just want to focus the control, we want to trigger it as if we had clicked it. Qt 6.8 introduced an animateClick method on buttons that briefly flashes the button as a reminder of what’s about to happen and then triggers it. For controls without this features, focus is set as before, albeit with ShortcutFocusReason to tell the control that it was focused as a result of a shortcut press. A ComboBox for instance reacts differently depending on how it got activated. I then also made sure no mnemonic is assigned to the label next to a control when the control itself already had one.

With those improvements done, I tested various Qt Quick applications and settings modules for their mnemonics. The “Display & Monitor” settings barely had any working ones. The thing is: FormLayout’s labels by default are attached to the Item to which the label was added. In case of KScreen, we often used a RowLayout to place a control an a “contextual help button” (the little (i) button with more information) next to it. Since RowLayout isn’t an interactive item, no mnemonic was assigned for the given row. Luckily, you can explicitly set buddyFor and tell it what the relevant control is. Doing that I made most of KScreen’s settings reachable by Alt key combinations. While at it, I explicitly set the letter H for the HDR check box.
Now that you’ve seen me improve our mnemonic machinery, what can you do to make an application more accessible this way? Press and hold Alt, see what shortcuts get assigned, try triggering the underlined letter using Alt+letter:
- If there’s a FormLayout and the control isn’t reachable, check that there’s a proper buddyFor set.
- For obvious abbreviation and words, consider to set a mnemonic explicitly so the letter used is consistent and predictable, like the “Enable &HDR” in Display settings
- For custom controls not based on Qt Quick Controls, you can use Kirigami.MnemonicData to register your control with our Mnemonic infrastructure and assign the shortcut it generated to a Shortcut item.
- Consider disabling mnemonics using Kirigami.MnemonicData.enabled where it doesn’t make much sense to have them. e.g. controls in lists. Each one would just get a subsequent letter in its word assigned, reducing the pool of available letters for the important ones
- If a control doesn’t show an underlined letter, try Alt+first letter in the label. Maybe it has one that doesn’t show up for a reason?
- Finally: Report or fix bugs you find!
Great Work.
Would it be possible to Long Press Alt and highlight the Shurtcuts, Like MS Office do.
What for? The letter is underlined and that’s much less intrusive than a big box showing the letter.
Cause the big boxes are much more visible for example if you want to learn the shortcuts or for visible impaired people. Shortcuts are very usefull to navigate in a programm. Make Them all visible can’t bei a bad Idea (only after long press alt Key)
TL;DR mnemonics are *very* broken right now and MS Office’s way (or Vimium’s way) really is far better. Read on for details.
TL;DR 2: For what? For decoupling the “mnemonic” from the label (you cannot assume the label has characters corresponding to existing keys) and for preventing layout shifts
Mnemonics assume the language uses latin characters. If the language doesn’t, automatic mnemonics might as well not exist (__新__增 isn’t a key; this has been in shipped code for years) and it’s up to translators to attach extremely ugly parens to let the UI toolkit assign mnemonics to, like “睡眠(P)” “桌布(W)”. Is that less intrusive than an actual UI element? Plus, when it’s assigned manually like that multiple elements using the same label now are no longer able to be distinguished.
My language will get crude as I describe the frustration as a user, but know that I do try to do what I can to improve things. I am the current most active Traditional Chinese translator for KDE, and I use Japanese and Traditional Chinese for my system.
When Alt is held, there is no need to stay out of the way. **When Alt is being held**. And when Alt isn’t held it can stay away. Kirigami (or Qt Quick or somewhere along the line) hides these parenthesis mnemonics, which sounds nice on paper but are terrible as implemented:
– Adding text causes layout shift
– At least on nightly builds they don’t work anyways (I haven’t done the work to narrow this down yet, but just switch to zh_TW and try navigating kcm_touchpad with mnemonics; that’s a page I’ve attempted to add back manual mnemonics)
– (BUG 498306) Updates…(3)(&U) (remember we cannot assume translated text has characters that are available om the keyboard; the real string is “更新…(3)(&U)”) get hidden as “Updates…(3” and has been this way for Years, unnoticed because overlap between languages getting bitten by this and development contributors is approximately 0
Maybe you could help FreeCAD to solve their Qt mnemonics problems:
https://github.com/FreeCAD/FreeCAD/issues/16640