mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-25 15:34:13 +01:00
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:
+20
-1
@@ -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()
|
||||
|
||||
@@ -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_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user