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
This commit is contained in:
Jonathan White committed 2026-09-19 17:45:52 -04:00
1 parent 5ac1b0c98d
commit 5ec5ba27ce
3 files changed
+25 -7

No files matched your search

+5 -5
View File
@@ -5807,10 +5807,6 @@ Are you sure you want to continue with this file?</source>
<source>&amp;Tools</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>View</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Theme</source>
<translation type="unfinished"></translation>
@@ -6460,7 +6456,7 @@ This version is not meant for production use.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Clear all identities in ssh-agent</source>
<source>&amp;View</source>
<translation type="unfinished"></translation>
</message>
<message>
@@ -6501,6 +6497,10 @@ This version is not meant for production use.</source>
<numerusform></numerusform>
</translation>
</message>
<message>
<source>Clear all identities in ssh-agent</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ManageDatabase</name>
+1 -1
View File
@@ -377,7 +377,7 @@
</widget>
<widget class="QMenu" name="menuView">
<property name="title">
<string>View</string>
<string>&amp;View</string>
</property>
<widget class="QMenu" name="menuTheme">
<property name="title">
+19 -1
View File
@@ -29,6 +29,7 @@
#include <QFile>
#include <QHeaderView>
#include <QListView>
#include <QMenuBar>
#include <QPainter>
#include <QPainterPath>
#include <QPoint>
@@ -4685,7 +4686,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<const QMenu*>(widget);
if (menu) {
auto p = menu->parentWidget();
while (p) {
auto mb = qobject_cast<QMenuBar*>(p);
if (mb && mb->hasFocus()) {
return 1;
}
p = p->parentWidget();
}
}
auto mb = qobject_cast<const QMenuBar*>(widget);
return (mb && mb->hasFocus()) ? 1 : 0;
#else
return 0;
#endif
}
case SH_Widget_Animate:
return 1;