Fix disabled and inactive group palettes for windows native style
The dark mode related changes for windows didn't update disabled and inactive group palettes, and this makes text in certain context (such as menu bar) appear with enabled color. The windows theme API populateLightSystemPalette() is responsible for this and it updates palettes for color roles and certain inactive scenarios but not for disabled. This patch set makes existing systemPalette(Qt::ColorScheme) to be available in QWindowsTheme and it updates palette depending on color scheme. From now on, this API updates palettes for windows native style. Its to be noted that window native style use light palette irrespective of color scheme. Fixes: QTBUG-114821 Pick-to: 6.5 6.6 Change-Id: Iff4f35900293b8e7030ec121ca21856daa094dc0 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
1c4dbd14ae
commit
491534006e
@ -420,7 +420,7 @@ struct Q_GUI_EXPORT QWindowsApplication
|
||||
virtual QVariant gpu() const = 0; // internal, used by qtdiag
|
||||
virtual QVariant gpuList() const = 0;
|
||||
|
||||
virtual void lightSystemPalette(QPalette &pal) const = 0;
|
||||
virtual void populateLightSystemPalette(QPalette &pal) const = 0;
|
||||
};
|
||||
#endif // Q_OS_WIN
|
||||
|
||||
|
@ -143,9 +143,9 @@ QVariant QWindowsApplication::gpuList() const
|
||||
return result;
|
||||
}
|
||||
|
||||
void QWindowsApplication::lightSystemPalette(QPalette &result) const
|
||||
void QWindowsApplication::populateLightSystemPalette(QPalette &result) const
|
||||
{
|
||||
QWindowsTheme::populateLightSystemBasePalette(result);
|
||||
result = QWindowsTheme::systemPalette(Qt::ColorScheme::Light);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -43,7 +43,7 @@ public:
|
||||
QVariant gpu() const override;
|
||||
QVariant gpuList() const override;
|
||||
|
||||
void lightSystemPalette(QPalette &palette) const override;
|
||||
void populateLightSystemPalette(QPalette &palette) const override;
|
||||
|
||||
private:
|
||||
WindowActivationBehavior m_windowActivationBehavior = DefaultActivateWindow;
|
||||
|
@ -241,7 +241,7 @@ static QColor placeHolderColor(QColor textColor)
|
||||
This is used when the theme is light mode, and when the theme is dark but the
|
||||
application doesn't support dark mode. In the latter case, we need to check.
|
||||
*/
|
||||
void QWindowsTheme::populateLightSystemBasePalette(QPalette &result)
|
||||
static void populateLightSystemBasePalette(QPalette &result)
|
||||
{
|
||||
const QColor background = getSysColor(COLOR_BTNFACE);
|
||||
const QColor textColor = getSysColor(COLOR_WINDOWTEXT);
|
||||
@ -354,39 +354,6 @@ static void populateDarkSystemBasePalette(QPalette &result)
|
||||
result.setColor(QPalette::All, QPalette::AccentColor, accent);
|
||||
}
|
||||
|
||||
static QPalette systemPalette(bool light)
|
||||
{
|
||||
QPalette result = standardPalette();
|
||||
if (light)
|
||||
QWindowsTheme::populateLightSystemBasePalette(result);
|
||||
else
|
||||
populateDarkSystemBasePalette(result);
|
||||
|
||||
if (result.window() != result.base()) {
|
||||
result.setColor(QPalette::Inactive, QPalette::Highlight,
|
||||
result.color(QPalette::Inactive, QPalette::Window));
|
||||
result.setColor(QPalette::Inactive, QPalette::HighlightedText,
|
||||
result.color(QPalette::Inactive, QPalette::Text));
|
||||
result.setColor(QPalette::Inactive, QPalette::AccentColor,
|
||||
result.color(QPalette::Inactive, QPalette::Window));
|
||||
}
|
||||
|
||||
const QColor disabled = mixColors(result.windowText().color(), result.button().color());
|
||||
|
||||
result.setColorGroup(QPalette::Disabled, result.windowText(), result.button(),
|
||||
result.light(), result.dark(), result.mid(),
|
||||
result.text(), result.brightText(), result.base(),
|
||||
result.window());
|
||||
result.setColor(QPalette::Disabled, QPalette::WindowText, disabled);
|
||||
result.setColor(QPalette::Disabled, QPalette::Text, disabled);
|
||||
result.setColor(QPalette::Disabled, QPalette::ButtonText, disabled);
|
||||
result.setColor(QPalette::Disabled, QPalette::Highlight, result.color(QPalette::Highlight));
|
||||
result.setColor(QPalette::Disabled, QPalette::HighlightedText, result.color(QPalette::HighlightedText));
|
||||
result.setColor(QPalette::Disabled, QPalette::AccentColor, disabled);
|
||||
result.setColor(QPalette::Disabled, QPalette::Base, result.window().color());
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline QPalette toolTipPalette(const QPalette &systemPalette, bool light)
|
||||
{
|
||||
QPalette result(systemPalette);
|
||||
@ -579,7 +546,7 @@ void QWindowsTheme::refreshPalettes()
|
||||
!QWindowsContext::isDarkMode()
|
||||
|| !QWindowsIntegration::instance()->darkModeHandling().testFlag(QWindowsApplication::DarkModeStyle);
|
||||
clearPalettes();
|
||||
m_palettes[SystemPalette] = new QPalette(systemPalette(light));
|
||||
m_palettes[SystemPalette] = new QPalette(QWindowsTheme::systemPalette(light ? Qt::ColorScheme::Light : Qt::ColorScheme::Dark));
|
||||
m_palettes[ToolTipPalette] = new QPalette(toolTipPalette(*m_palettes[SystemPalette], light));
|
||||
m_palettes[MenuPalette] = new QPalette(menuPalette(*m_palettes[SystemPalette], light));
|
||||
m_palettes[MenuBarPalette] = menuBarPalette(*m_palettes[MenuPalette], light);
|
||||
@ -603,6 +570,47 @@ void QWindowsTheme::refreshPalettes()
|
||||
}
|
||||
}
|
||||
|
||||
QPalette QWindowsTheme::systemPalette(Qt::ColorScheme colorScheme)
|
||||
{
|
||||
QPalette result = standardPalette();
|
||||
|
||||
switch (colorScheme) {
|
||||
case Qt::ColorScheme::Light:
|
||||
populateLightSystemBasePalette(result);
|
||||
break;
|
||||
case Qt::ColorScheme::Dark:
|
||||
populateDarkSystemBasePalette(result);
|
||||
break;
|
||||
default:
|
||||
qFatal("Unknown color scheme");
|
||||
break;
|
||||
}
|
||||
|
||||
if (result.window() != result.base()) {
|
||||
result.setColor(QPalette::Inactive, QPalette::Highlight,
|
||||
result.color(QPalette::Inactive, QPalette::Window));
|
||||
result.setColor(QPalette::Inactive, QPalette::HighlightedText,
|
||||
result.color(QPalette::Inactive, QPalette::Text));
|
||||
result.setColor(QPalette::Inactive, QPalette::AccentColor,
|
||||
result.color(QPalette::Inactive, QPalette::Window));
|
||||
}
|
||||
|
||||
const QColor disabled = mixColors(result.windowText().color(), result.button().color());
|
||||
|
||||
result.setColorGroup(QPalette::Disabled, result.windowText(), result.button(),
|
||||
result.light(), result.dark(), result.mid(),
|
||||
result.text(), result.brightText(), result.base(),
|
||||
result.window());
|
||||
result.setColor(QPalette::Disabled, QPalette::WindowText, disabled);
|
||||
result.setColor(QPalette::Disabled, QPalette::Text, disabled);
|
||||
result.setColor(QPalette::Disabled, QPalette::ButtonText, disabled);
|
||||
result.setColor(QPalette::Disabled, QPalette::Highlight, result.color(QPalette::Highlight));
|
||||
result.setColor(QPalette::Disabled, QPalette::HighlightedText, result.color(QPalette::HighlightedText));
|
||||
result.setColor(QPalette::Disabled, QPalette::AccentColor, disabled);
|
||||
result.setColor(QPalette::Disabled, QPalette::Base, result.window().color());
|
||||
return result;
|
||||
}
|
||||
|
||||
void QWindowsTheme::clearFonts()
|
||||
{
|
||||
qDeleteAll(m_fonts, m_fonts + NFonts);
|
||||
|
@ -61,7 +61,7 @@ public:
|
||||
|
||||
static const char *name;
|
||||
|
||||
static void populateLightSystemBasePalette(QPalette &result);
|
||||
static QPalette systemPalette(Qt::ColorScheme);
|
||||
|
||||
private:
|
||||
void clearPalettes();
|
||||
|
@ -4815,7 +4815,7 @@ void QWindowsVistaStyle::polish(QPalette &pal)
|
||||
// Overwrite with the light system palette.
|
||||
using QWindowsApplication = QNativeInterface::Private::QWindowsApplication;
|
||||
if (auto nativeWindowsApp = dynamic_cast<QWindowsApplication *>(QGuiApplicationPrivate::platformIntegration()))
|
||||
nativeWindowsApp->lightSystemPalette(pal);
|
||||
nativeWindowsApp->populateLightSystemPalette(pal);
|
||||
}
|
||||
|
||||
QPixmapCache::clear();
|
||||
|
Loading…
Reference in New Issue
Block a user