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 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-10-24 06:06:33 +13:00
parent 8d448a8117
commit 2a6de652f7
2 changed files with 23 additions and 1 deletions
+20 -1
View File
@@ -21,6 +21,7 @@
#include <QImage>
#include <QPainter>
#include <QPixmap>
#include <QStyleHints>
#include <QStyleOption>
#include <QWidget>
@@ -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<const QStyleOptionMenuItem *>(option);
if (item && !item->icon.isNull()