Mnemonics, Mnemonics Everywhere
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!