Merge pull request #1597 from ispyisail/fix/1591-win11-menu-icons

Fix hovered menu icons vanishing on Windows 11 with a light colour
This commit is contained in:
Laurent Trinques
2026-10-24 02:40:52 +02:00
committed by GitHub
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()
+3
View File
@@ -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<QString, QIcon> menu_icons_;
};