From b12b67be60ef9d94355cc10e3b58c0134a00a008 Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Sun, 19 Jan 2025 12:06:35 -0500 Subject: [PATCH] Enable access key underline of menu bar items when focused * Fixes #7325 Qt 5.x defaults to always show mnemonic underlines in menus. Qt 6.x fixes this, but we can't port the fix since it relies on private theme namespaces. Anyway, to get around this, simply check if the widget is a menubar and focused. If so, we draw the underlines. Only applies when the user actually presses ALT so this is desired behavior. NOTE: Underlines in menus will disappear once you focus on the menu, still working on this --- share/translations/keepassxc_en.ts | 8 ++++---- src/gui/MainWindow.ui | 2 +- src/gui/styles/base/BaseStyle.cpp | 20 +++++++++++++++++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/share/translations/keepassxc_en.ts b/share/translations/keepassxc_en.ts index 0cf445a86..0148b6fce 100644 --- a/share/translations/keepassxc_en.ts +++ b/share/translations/keepassxc_en.ts @@ -5561,10 +5561,6 @@ Are you sure you want to continue with this file? &Tools - - View - - Theme @@ -6230,6 +6226,10 @@ Expect some bugs and minor issues, this version is meant for testing purposes.E&xpire Entry… + + &View + + ManageDatabase diff --git a/src/gui/MainWindow.ui b/src/gui/MainWindow.ui index c84727c3e..7b4da9171 100644 --- a/src/gui/MainWindow.ui +++ b/src/gui/MainWindow.ui @@ -373,7 +373,7 @@ - View + &View diff --git a/src/gui/styles/base/BaseStyle.cpp b/src/gui/styles/base/BaseStyle.cpp index 9cb844d70..403b99d90 100644 --- a/src/gui/styles/base/BaseStyle.cpp +++ b/src/gui/styles/base/BaseStyle.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -4680,7 +4681,24 @@ int BaseStyle::styleHint(StyleHint hint, case SH_WindowFrame_Mask: return 0; case SH_UnderlineShortcut: { - return false; +#if defined(Q_OS_WIN) or defined(Q_OS_LINUX) + // Only show underline shortcuts if the user focused with ALT (Win/Linux only) + auto menu = qobject_cast(widget); + if (menu) { + auto p = menu->parentWidget(); + while (p) { + auto mb = qobject_cast(p); + if (mb && mb->hasFocus()) { + return 1; + } + p = p->parentWidget(); + } + } + auto mb = qobject_cast(widget); + return (mb && mb->hasFocus()) ? 1 : 0; +#else + return 0; +#endif } case SH_Widget_Animate: return 1;