From 2a6de652f77354ece25f14f0d03a2b339d9d5774 Mon Sep 17 00:00:00 2001 From: ispyisail Date: Sat, 24 Oct 2026 06:06:33 +1300 Subject: [PATCH] Fix hovered menu icons vanishing in the Windows 11 style A highlighted menu item's icon was redrawn in the highlighted-text color, white in most palettes, for the highlight bar Fusion draws. The Windows 11 style draws a pale fill and the normal text color instead, so the white icon disappeared on light colors (issue #1591). Leave the icon to the ordinary hover tint there, except in high contrast, where that style does draw a highlight bar. Co-Authored-By: Claude Opus 5.5 --- sources/qetstyle.cpp | 21 ++++++++++++++++++++- sources/qetstyle.h | 3 +++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/sources/qetstyle.cpp b/sources/qetstyle.cpp index d8a292240..c5ea19e03 100644 --- a/sources/qetstyle.cpp +++ b/sources/qetstyle.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -136,6 +137,24 @@ QIcon QETStyle::menuIcon(const QIcon &icon, const QPalette &palette, int size, q return result; } +/** + @brief QETStyle::hasMenuHighlightBar + False for the Windows 11 style outside high contrast: it marks a + highlighted menu item with a pale fill and keeps the normal text + color, so an icon in the highlighted-text color would vanish on it + (issue #1591). +*/ +bool QETStyle::hasMenuHighlightBar() const +{ + if (objectName().compare(QLatin1String("windows11"), Qt::CaseInsensitive) != 0) + return true; +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) + return QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Unknown; +#else + return true; +#endif +} + /** @brief QETStyle::drawControl CE_MenuItem with an icon and a highlight: swap the icon for menuIcon() @@ -147,7 +166,7 @@ void QETStyle::drawControl(ControlElement element, QPainter *painter, const QWidget *widget) const { - if (element == CE_MenuItem) + if (element == CE_MenuItem && hasMenuHighlightBar()) { const auto *item = qstyleoption_cast(option); if (item && !item->icon.isNull() diff --git a/sources/qetstyle.h b/sources/qetstyle.h index 04e35ea0e..229659465 100644 --- a/sources/qetstyle.h +++ b/sources/qetstyle.h @@ -41,6 +41,8 @@ vanish. The generated pixmap is cached per icon and cannot tell a menu from a toolbar, so drawControl(CE_MenuItem) hands the base style an icon whose Active pixmap is the icon in the highlighted-text color. + The Windows 11 style draws no highlight bar (see hasMenuHighlightBar()), + so its highlighted menu items keep the hover tint. */ class QETStyle : public QProxyStyle { @@ -66,6 +68,7 @@ class QETStyle : public QProxyStyle static QPixmap tinted(const QPixmap &pixmap, const QColor &color); private: + bool hasMenuHighlightBar() const; QIcon menuIcon(const QIcon &icon, const QPalette &palette, int size, qreal dpr) const; mutable QHash menu_icons_; };