From a8c6958a875a6c6ad67b5741a5daa89f5340710c Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Fri, 21 Oct 2022 22:42:36 +0200 Subject: [PATCH] Add QPlatformTheme::MenuBarFocusOnAltPressRelease MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Windows, pressing and releasing the Alt key moves focus to the menubar. This is implemented in widgets, but not in Qt Quick. Add a new theme hint so that we can make Qt behave natively on all platforms, and make the common style's respective styleHint default to the theme hint. Change-Id: I101bec56afd51e81ebb128c288f8a1e9b7efedb4 Reviewed-by: Tor Arne Vestbø --- src/gui/kernel/qplatformtheme.cpp | 2 ++ src/gui/kernel/qplatformtheme.h | 3 ++- src/plugins/platforms/windows/qwindowstheme.cpp | 2 ++ src/widgets/styles/qcommonstyle.cpp | 5 ++++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/gui/kernel/qplatformtheme.cpp b/src/gui/kernel/qplatformtheme.cpp index fb1c27a15a..ec4b9c2b86 100644 --- a/src/gui/kernel/qplatformtheme.cpp +++ b/src/gui/kernel/qplatformtheme.cpp @@ -625,6 +625,8 @@ QVariant QPlatformTheme::defaultThemeHint(ThemeHint hint) return QVariant(2500); case FlickDeceleration: return QVariant(5000); + case MenuBarFocusOnAltPressRelease: + return false; } return QVariant(); } diff --git a/src/gui/kernel/qplatformtheme.h b/src/gui/kernel/qplatformtheme.h index 1fa8c12b48..1b7fc85c81 100644 --- a/src/gui/kernel/qplatformtheme.h +++ b/src/gui/kernel/qplatformtheme.h @@ -91,7 +91,8 @@ public: SetFocusOnTouchRelease, FlickStartDistance, FlickMaximumVelocity, - FlickDeceleration + FlickDeceleration, + MenuBarFocusOnAltPressRelease }; Q_ENUM(ThemeHint) diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp index 3704fce15e..eeb4ac4067 100644 --- a/src/plugins/platforms/windows/qwindowstheme.cpp +++ b/src/plugins/platforms/windows/qwindowstheme.cpp @@ -558,6 +558,8 @@ QVariant QWindowsTheme::themeHint(ThemeHint hint) const } case MouseDoubleClickDistance: return GetSystemMetrics(SM_CXDOUBLECLK); + case MenuBarFocusOnAltPressRelease: + return true; default: break; } diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 01fb688469..2cb9bc00ba 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -5384,7 +5384,6 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget case SH_Menu_AllowActiveAndDisabled: case SH_Menu_SpaceActivatesItem: case SH_ScrollView_FrameOnlyAroundContents: - case SH_MenuBar_AltKeyNavigation: case SH_ComboBox_ListMouseTracking: case SH_Menu_MouseTracking: case SH_MenuBar_MouseTracking: @@ -5410,6 +5409,10 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget case SH_Table_AlwaysDrawLeftTopGridLines: ret = false; break; + case SH_MenuBar_AltKeyNavigation: + if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) + ret = theme->themeHint(QPlatformTheme::MenuBarFocusOnAltPressRelease).toBool(); + break; case SH_CustomBase: // Added to get compiler errors when a style hint is missing ret = false;