diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2020-09-21 01:07:32 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-21 01:07:32 +0000 |
commit | 3cc3ef246ad71c463c8952bcc96984b25d85b516 (patch) | |
tree | 1e1426a2a71429ebf29bb0cfbfb0f2ad66d0d4dd | |
parent | abb14f0ba4ef4c072ae330bcefa0419b701bc88b (diff) | |
parent | 32c8c82b963e349a8345a24c7a5e3597632c2f9c (diff) |
Merge pull request #1169 from opentrack/feature_windows_dark_theme
Apply dark theme on Windows if user enabled it in system settings.
-rw-r--r-- | gui/init.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/gui/init.cpp b/gui/init.cpp index 3aae5772..2b7b01ad 100644 --- a/gui/init.cpp +++ b/gui/init.cpp @@ -159,6 +159,39 @@ static void qdebug_to_console(QtMsgType loglevel, const QMessageLogContext& ctx, #ifdef _WIN32 +static void apply_dark_windows_theme_if_needed() +{ + // On Windows apply dark theme if requested by user settings + QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", QSettings::NativeFormat); + if (settings.value("AppsUseLightTheme") == 0) { + qApp->setStyle(QStyleFactory::create("Dark")); + QPalette darkPalette; + QColor darkColor = QColor(45, 45, 45); + QColor disabledColor = QColor(127, 127, 127); + darkPalette.setColor(QPalette::Window, darkColor); + darkPalette.setColor(QPalette::WindowText, Qt::white); + darkPalette.setColor(QPalette::Base, QColor(18, 18, 18)); + darkPalette.setColor(QPalette::AlternateBase, darkColor); + darkPalette.setColor(QPalette::ToolTipBase, Qt::white); + darkPalette.setColor(QPalette::ToolTipText, Qt::white); + darkPalette.setColor(QPalette::Text, Qt::white); + darkPalette.setColor(QPalette::Disabled, QPalette::Text, disabledColor); + darkPalette.setColor(QPalette::Button, darkColor); + darkPalette.setColor(QPalette::ButtonText, Qt::white); + darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, disabledColor); + darkPalette.setColor(QPalette::BrightText, Qt::red); + darkPalette.setColor(QPalette::Link, QColor(42, 130, 218)); + + darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218)); + darkPalette.setColor(QPalette::HighlightedText, Qt::black); + darkPalette.setColor(QPalette::Disabled, QPalette::HighlightedText, disabledColor); + + qApp->setPalette(darkPalette); + + qApp->setStyleSheet("QToolTip { color: #ffffff; background-color: #2a82da; border: 1px solid white; }"); + } +} + static void add_win32_path() { // see https://software.intel.com/en-us/articles/limitation-to-the-length-of-the-system-path-variable @@ -270,6 +303,7 @@ int otr_main(int argc, char** argv, std::function<std::unique_ptr<QWidget>()> co QApplication app(argc, argv); #ifdef _WIN32 + apply_dark_windows_theme_if_needed(); add_win32_path(); attach_parent_console(); #endif |