Always use Fusion style, light theme included

This commit is contained in:
Ada 2025-04-27 19:52:49 +10:00
parent a176ca6c51
commit b4a46e3c42
3 changed files with 34 additions and 25 deletions

View file

@ -248,9 +248,6 @@ Application::Application(
qInstallMessageHandler(messageHandler); qInstallMessageHandler(messageHandler);
DependencyManager::set<PathUtils>(); DependencyManager::set<PathUtils>();
_startupThemeStyleName = qApp->style()->objectName();
_startupThemePalette = qApp->palette();
} }
Application::~Application() { Application::~Application() {

View file

@ -809,10 +809,6 @@ private:
Setting::Handle<bool> _miniTabletEnabledSetting; Setting::Handle<bool> _miniTabletEnabledSetting;
Setting::Handle<bool> _keepLogWindowOnTop { "keepLogWindowOnTop", false }; Setting::Handle<bool> _keepLogWindowOnTop { "keepLogWindowOnTop", false };
// to allow switching between system/light and dark theme without needing a restart
QString _startupThemeStyleName;
QPalette _startupThemePalette;
void updateThemeColors(); void updateThemeColors();

View file

@ -16,6 +16,7 @@
#include "Application.h" #include "Application.h"
#include <QtQml/QQmlContext> #include <QtQml/QQmlContext>
#include <QStyle>
#include <QStyleFactory> #include <QStyleFactory>
#include <AddressManager.h> #include <AddressManager.h>
@ -794,26 +795,41 @@ void Application::setPreferredCursor(const QString& cursorName) {
} }
void Application::updateThemeColors() { void Application::updateThemeColors() {
// builtin style that exists on all platforms
// NOTE: in Qt5 the Fusion style with a dark palette has
// checkboxes with very low contrast, this was fixed in Qt6.5
auto style = QStyleFactory::create("Fusion");
QPalette palette = style->standardPalette();
if (_darkTheme.get()) { if (_darkTheme.get()) {
qApp->setStyle(QStyleFactory::create("Fusion")); // builtin style that always exists palette.setColor(QPalette::Window, QColor(48, 48, 48));
auto palette = QPalette( palette.setColor(QPalette::WindowText, QColor(224, 224, 224));
QColor(224, 224, 224), // windowText
QColor(48, 48, 48), // button palette.setColor(QPalette::Base, QColor(40, 40, 40));
QColor(72, 72, 72), // light palette.setColor(QPalette::AlternateBase, QColor(44, 44, 44));
QColor(24, 24, 24), // dark
QColor(48, 48, 48), // mid palette.setColor(QPalette::Light, QColor(72, 72, 72));
QColor(224, 224, 224), // text palette.setColor(QPalette::Midlight, QColor(64, 64, 64));
QColor(255, 255, 255), // brightText palette.setColor(QPalette::Button, QColor(40, 40, 40));
QColor(48, 48, 48), // base palette.setColor(QPalette::Mid, QColor(32, 32, 32));
QColor(48, 48, 48) // window palette.setColor(QPalette::Dark, QColor(20, 20, 20));
); palette.setColor(QPalette::Shadow, QColor(0, 0, 0));
qApp->setPalette(palette);
qApp->getPrimaryMenu()->setPalette(palette); // weird Qt bug workaround palette.setColor(QPalette::Text, QColor(224, 224, 224));
} else { palette.setColor(QPalette::ButtonText, QColor(224, 224, 224));
qApp->setStyle(QStyleFactory::create(_startupThemeStyleName)); palette.setColor(QPalette::BrightText, QColor(255, 255, 255));
qApp->setPalette(_startupThemePalette);
qApp->getPrimaryMenu()->setPalette(_startupThemePalette); // weird Qt bug workaround palette.setColor(QPalette::Highlight, QColor(21, 83, 158));
palette.setColor(QPalette::HighlightedText, QColor(255, 255, 255));
palette.setColor(QPalette::Link, QColor(95, 189, 252));
palette.setColor(QPalette::LinkVisited, QColor(192, 95, 252));
} }
qApp->setStyle(style);
qApp->setPalette(palette);
qApp->getPrimaryMenu()->setPalette(palette); // weird Qt bug workaround
} }
void Application::setDarkThemePreference(bool value) { void Application::setDarkThemePreference(bool value) {