Skip to content

Commit

Permalink
Add prefs to allow use of inherent Qt dark theme on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
dougmassay committed Jul 28, 2024
1 parent 06892af commit 487176d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
13 changes: 13 additions & 0 deletions SettingsStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static QString KEY_UI_DICTIONARY = SETTINGS_GROUP + "/" + "ui_dictionary";

static QString KEY_UI_FONT = SETTINGS_GROUP + "/" + "ui_font";
static QString KEY_ORIGINAL_UI_FONT = SETTINGS_GROUP + "/" + "original_ui_font";
static QString KEY_UI_CUSTOM_DARK_THEME = SETTINGS_GROUP + "/" + "ui_custom_dark_theme";

static QString KEY_HIGHDPI_SETTING = SETTINGS_GROUP + "/" + "high_dpi";
static QString KEY_DISABLEGPU_SETTING = SETTINGS_GROUP + "/" + "disable_gpu";
Expand Down Expand Up @@ -145,6 +146,12 @@ bool SettingsStore::spellCheck()
}
#endif

bool SettingsStore::uiUseCustomDarkTheme()
{
clearSettingsGroup();
return value(KEY_UI_CUSTOM_DARK_THEME, true).toBool();
}

float SettingsStore::zoomImage()
{
clearSettingsGroup();
Expand Down Expand Up @@ -304,6 +311,12 @@ void SettingsStore::setSpellCheck(bool enabled)
}
#endif

void SettingsStore::setUiUseCustomDarkTheme(bool enable)
{
clearSettingsGroup();
setValue(KEY_UI_CUSTOM_DARK_THEME, enable);
}

void SettingsStore::setZoomImage(float zoom)
{
clearSettingsGroup();
Expand Down
4 changes: 4 additions & 0 deletions SettingsStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class SettingsStore : public QSettings

// bool spellCheck();

bool uiUseCustomDarkTheme();

/**
* The zoom factor used by the component.
*
Expand Down Expand Up @@ -157,6 +159,8 @@ public slots:

// void setSpellCheck(bool enabled);

void setUiUseCustomDarkTheme(bool enable);

/**
* Set the zoom factor used by the component.
*
Expand Down
14 changes: 6 additions & 8 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ int main(int argc, char *argv[])
#ifdef Q_OS_WIN32
QStyle* astyle = QStyleFactory::create("fusion");
app.setStyle(astyle);
// Use our custom Windows dark theme unless user opts-in with preference
if (Utility::WindowsShouldUseDarkMode() && settings.uiUseCustomDarkTheme()) {
// Apply custom dark style
app.setStyle(new PEDarkStyle);
app.setPalette(QApplication::style()->standardPalette());
}
#endif // Q_OS_WIN32

#if !defined(Q_OS_MAC) && !defined(Q_OS_WIN32) // *nix
Expand All @@ -270,14 +276,6 @@ int main(int argc, char *argv[])
app.setStyle(astyle);
#endif // *nix

#ifndef Q_OS_MAC
if (Utility::WindowsShouldUseDarkMode()) {
// Apply custom dark style
app.setStyle(new PEDarkStyle);
app.setPalette(QApplication::style()->standardPalette());
}
#endif

// it seems that any time there is stylesheet used, system dark-light palette
// changes are not propagated to widgets with stylesheets (See QTBUG-124268).
// This in turn prevents some widgets from properly geting repainted with the new
Expand Down

0 comments on commit 487176d

Please sign in to comment.