Refresh custom colors once color scheme is changed

PR #20588.
This commit is contained in:
Vladimir Golovnev 2024-03-23 11:32:07 +03:00 committed by GitHub
parent 25b7972f88
commit ce013f132f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 195 additions and 126 deletions

View file

@ -30,6 +30,7 @@
#include "uithememanager.h"
#include <QApplication>
#include <QPalette>
#include <QPixmapCache>
#include <QResource>
@ -79,11 +80,8 @@ UIThemeManager::UIThemeManager()
, m_useSystemIcons {Preferences::instance()->useSystemIcons()}
#endif
{
connect(QApplication::styleHints(), &QStyleHints::colorSchemeChanged, this, []
{
// workaround to refresh styled controls once color scheme is changed
QApplication::setStyle(QApplication::style()->name());
});
// NOTE: Qt::QueuedConnection can be omitted as soon as support for Qt 6.5 is dropped
connect(QApplication::styleHints(), &QStyleHints::colorSchemeChanged, this, &UIThemeManager::onColorSchemeChanged, Qt::QueuedConnection);
if (m_useCustomTheme)
{
@ -122,6 +120,14 @@ void UIThemeManager::applyStyleSheet() const
qApp->setStyleSheet(QString::fromUtf8(m_themeSource->readStyleSheet()));
}
void UIThemeManager::onColorSchemeChanged()
{
emit themeChanged();
// workaround to refresh styled controls once color scheme is changed
QApplication::setStyle(QApplication::style()->name());
}
QIcon UIThemeManager::getIcon(const QString &iconId, [[maybe_unused]] const QString &fallback) const
{
const auto colorMode = isDarkTheme() ? ColorMode::Dark : ColorMode::Light;
@ -184,8 +190,6 @@ QPixmap UIThemeManager::getScaledPixmap(const QString &iconId, const int height)
QColor UIThemeManager::getColor(const QString &id) const
{
const QColor color = m_themeSource->getColor(id, (isDarkTheme() ? ColorMode::Dark : ColorMode::Light));
Q_ASSERT(color.isValid());
return color;
}