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_; };