Skip to content
This repository has been archived by the owner. It is now read-only.

Commit 4905beb

Browse files
committed
Apply new platform palette without overriding app paletee
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.
1 parent 55dba87 commit 4905beb

File tree

2 files changed

+9
-28
lines changed

2 files changed

+9
-28
lines changed

src/qt6ct-qtplugin/qt6ctplatformtheme.cpp

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ QPlatformDialogHelper *Qt6CTPlatformTheme::createPlatformDialogHelper(DialogType
9292

9393
const QPalette *Qt6CTPlatformTheme::palette(QPlatformTheme::Palette type) const
9494
{
95-
qDebug() << Q_FUNC_INFO << type;
96-
return (m_usePalette && m_palette) ? m_palette.get() : QGenericUnixTheme::palette(type);
95+
if (type == QPlatformTheme::SystemPalette && !m_isIgnored)
96+
return &m_palette;
97+
return QPlatformTheme::palette(type);
9798
}
9899

99100
const QFont *Qt6CTPlatformTheme::font(QPlatformTheme::Font type) const
@@ -152,21 +153,10 @@ void Qt6CTPlatformTheme::applySettings()
152153
{
153154
if(!QGuiApplication::desktopSettingsAware() || m_isIgnored)
154155
{
155-
m_usePalette = false;
156156
m_update = true;
157157
return;
158158
}
159159

160-
if(!m_update)
161-
{
162-
//do not override application palette
163-
if(QCoreApplication::testAttribute(Qt::AA_SetPalette))
164-
{
165-
m_usePalette = false;
166-
qCDebug(lqt6ct) << "palette support is disabled";
167-
}
168-
}
169-
170160
QGuiApplication::setFont(m_generalFont); //apply font
171161

172162
#ifdef QT_WIDGETS_LIB
@@ -182,12 +172,6 @@ void Qt6CTPlatformTheme::applySettings()
182172
Qt6CT::reloadStyleInstanceSettings();
183173
}
184174

185-
if(!m_palette)
186-
m_palette = std::make_unique<QPalette>(qApp->style()->standardPalette());
187-
188-
if(m_update && m_usePalette)
189-
qApp->setPalette(*m_palette);
190-
191175
if(m_userStyleSheet != m_prevStyleSheet)
192176
{
193177
// prepend our stylesheet to that of the application
@@ -209,7 +193,10 @@ void Qt6CTPlatformTheme::applySettings()
209193
#endif
210194

211195
if(m_update)
196+
{
212197
QIconLoader::instance()->updateSystemTheme(); //apply icons
198+
QGuiApplication::setPalette(QGuiApplication::palette()); //apply palette
199+
}
213200

214201
#ifdef QT_WIDGETS_LIB
215202
if(hasWidgets() && m_update)
@@ -218,8 +205,6 @@ void Qt6CTPlatformTheme::applySettings()
218205
{
219206
QEvent e(QEvent::ThemeChange);
220207
QApplication::sendEvent(w, &e);
221-
if(m_palette && m_usePalette)
222-
w->setPalette(*m_palette);
223208
}
224209
}
225210
#endif
@@ -250,17 +235,16 @@ void Qt6CTPlatformTheme::updateSettings()
250235

251236
void Qt6CTPlatformTheme::readSettings()
252237
{
253-
m_palette.reset();
254-
255238
QSettings settings(Qt6CT::configFile(), QSettings::IniFormat);
256239

257240
settings.beginGroup("Appearance");
258241
m_style = settings.value("style", "Fusion").toString();
242+
m_palette = *QPlatformTheme::palette(SystemPalette);
259243
QString schemePath = settings.value("color_scheme_path").toString();
260244
if(!schemePath.isEmpty() && settings.value("custom_palette", false).toBool())
261245
{
262246
schemePath = Qt6CT::resolvePath(schemePath); //replace environment variables
263-
m_palette = std::make_unique<QPalette>(Qt6CT::loadColorScheme(schemePath, *QPlatformTheme::palette(SystemPalette)));
247+
m_palette = Qt6CT::loadColorScheme(schemePath, m_palette);
264248
}
265249
m_iconTheme = settings.value("icon_theme").toString();
266250
//load dialogs
@@ -338,8 +322,6 @@ void Qt6CTPlatformTheme::readSettings()
338322
QCoreApplication::setAttribute(Qt::AA_ForceRasterWidgets, true);
339323
else if(!m_isIgnored && forceRasterWidgets == Qt::Unchecked)
340324
QCoreApplication::setAttribute(Qt::AA_ForceRasterWidgets, false);
341-
if(m_isIgnored)
342-
m_usePalette = false;
343325
settings.endGroup();
344326
}
345327
}

src/qt6ct-qtplugin/qt6ctplatformtheme.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,14 @@ private slots:
8080
#endif
8181
QString loadStyleSheets(const QStringList &paths);
8282
QString m_style, m_iconTheme, m_userStyleSheet, m_prevStyleSheet;
83-
std::unique_ptr<QPalette> m_palette;
83+
QPalette m_palette;
8484
QFont m_generalFont, m_fixedFont;
8585
int m_doubleClickInterval;
8686
int m_cursorFlashTime;
8787
int m_uiEffects;
8888
int m_buttonBoxLayout;
8989
int m_keyboardScheme;
9090
bool m_update = false;
91-
bool m_usePalette = true;
9291
int m_toolButtonStyle = Qt::ToolButtonFollowStyle;
9392
int m_wheelScrollLines = 3;
9493
bool m_showShortcutsInContextMenus = false;

0 commit comments

Comments
 (0)