Skip to content

Commit

Permalink
Apply new platform palette without overriding app palette
Browse files Browse the repository at this point in the history
Currently when a palette is set by qt6ct, it can in some cases override
an app-specific palette. It would be nice if qt6ct would only set the
platform palette (i.e. QPlatformTheme::SystemPalette) and still allow
apps to set/adjust their own palette when desired.

Test case: start Audacious and select Dark theme in Audacious settings.
Then in qt6ct configuration, select "dusk" or "sand" color scheme. It
partially applies to Audacious (where it should not) and you end up with
an unusable mix of Audacious's color scheme and qt6ct's.

Port of the qt5ct patch from https://sourceforge.net/p/qt5ct/tickets/97/.
I have been using the patch in both qt5ct and qt6ct for quite some time
and have not seen any ill side effects.

trialuser02#48
  • Loading branch information
jlindgren90 committed May 11, 2024
1 parent 7db6735 commit 9f6600d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.
34 changes: 8 additions & 26 deletions src/qt6ct-qtplugin/qt6ctplatformtheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ QPlatformDialogHelper *Qt6CTPlatformTheme::createPlatformDialogHelper(DialogType

const QPalette *Qt6CTPlatformTheme::palette(QPlatformTheme::Palette type) const
{
qDebug() << Q_FUNC_INFO << type;
return (m_usePalette && m_palette) ? m_palette.get() : QGenericUnixTheme::palette(type);
if (type == QPlatformTheme::SystemPalette && !m_isIgnored)
return &m_palette;
return QPlatformTheme::palette(type);
}

const QFont *Qt6CTPlatformTheme::font(QPlatformTheme::Font type) const
Expand Down Expand Up @@ -152,21 +153,10 @@ void Qt6CTPlatformTheme::applySettings()
{
if(!QGuiApplication::desktopSettingsAware() || m_isIgnored)
{
m_usePalette = false;
m_update = true;
return;
}

if(!m_update)
{
//do not override application palette
if(QCoreApplication::testAttribute(Qt::AA_SetPalette))
{
m_usePalette = false;
qCDebug(lqt6ct) << "palette support is disabled";
}
}

QGuiApplication::setFont(m_generalFont); //apply font

#ifdef QT_WIDGETS_LIB
Expand All @@ -182,12 +172,6 @@ void Qt6CTPlatformTheme::applySettings()
Qt6CT::reloadStyleInstanceSettings();
}

if(!m_palette)
m_palette = std::make_unique<QPalette>(qApp->style()->standardPalette());

if(m_update && m_usePalette)
qApp->setPalette(*m_palette);

if(m_userStyleSheet != m_prevStyleSheet)
{
// prepend our stylesheet to that of the application
Expand All @@ -209,7 +193,10 @@ void Qt6CTPlatformTheme::applySettings()
#endif

if(m_update)
{
QIconLoader::instance()->updateSystemTheme(); //apply icons
QGuiApplication::setPalette(QGuiApplication::palette()); //apply palette
}

#ifdef QT_WIDGETS_LIB
if(hasWidgets() && m_update)
Expand All @@ -218,8 +205,6 @@ void Qt6CTPlatformTheme::applySettings()
{
QEvent e(QEvent::ThemeChange);
QApplication::sendEvent(w, &e);
if(m_palette && m_usePalette)
w->setPalette(*m_palette);
}
}
#endif
Expand Down Expand Up @@ -250,17 +235,16 @@ void Qt6CTPlatformTheme::updateSettings()

void Qt6CTPlatformTheme::readSettings()
{
m_palette.reset();

QSettings settings(Qt6CT::configFile(), QSettings::IniFormat);

settings.beginGroup("Appearance");
m_style = settings.value("style", "Fusion").toString();
m_palette = *QPlatformTheme::palette(SystemPalette);
QString schemePath = settings.value("color_scheme_path").toString();
if(!schemePath.isEmpty() && settings.value("custom_palette", false).toBool())
{
schemePath = Qt6CT::resolvePath(schemePath); //replace environment variables
m_palette = std::make_unique<QPalette>(Qt6CT::loadColorScheme(schemePath, *QPlatformTheme::palette(SystemPalette)));
m_palette = Qt6CT::loadColorScheme(schemePath, m_palette);
}
m_iconTheme = settings.value("icon_theme").toString();
//load dialogs
Expand Down Expand Up @@ -338,8 +322,6 @@ void Qt6CTPlatformTheme::readSettings()
QCoreApplication::setAttribute(Qt::AA_ForceRasterWidgets, true);
else if(!m_isIgnored && forceRasterWidgets == Qt::Unchecked)
QCoreApplication::setAttribute(Qt::AA_ForceRasterWidgets, false);
if(m_isIgnored)
m_usePalette = false;
settings.endGroup();
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/qt6ct-qtplugin/qt6ctplatformtheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,14 @@ private slots:
#endif
QString loadStyleSheets(const QStringList &paths);
QString m_style, m_iconTheme, m_userStyleSheet, m_prevStyleSheet;
std::unique_ptr<QPalette> m_palette;
QPalette m_palette;
QFont m_generalFont, m_fixedFont;
int m_doubleClickInterval;
int m_cursorFlashTime;
int m_uiEffects;
int m_buttonBoxLayout;
int m_keyboardScheme;
bool m_update = false;
bool m_usePalette = true;
int m_toolButtonStyle = Qt::ToolButtonFollowStyle;
int m_wheelScrollLines = 3;
bool m_showShortcutsInContextMenus = false;
Expand Down

0 comments on commit 9f6600d

Please sign in to comment.