Skip to content

Commit

Permalink
Further refine IsDarkMode test
Browse files Browse the repository at this point in the history
  • Loading branch information
dougmassay committed May 3, 2024
1 parent 4eeb362 commit cd4cad7
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/Misc/Utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,16 @@ QString Utility::DefinePrefsDir()

bool Utility::IsDarkMode()
{
#ifdef Q_OS_MAC
#if defined(Q_OS_MAC)
MainApplication *mainApplication = qobject_cast<MainApplication *>(qApp);
return mainApplication->isDarkMode();
#else // Windows, Linux and Other platforms
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
if (qApp->styleHints()->colorScheme() == Qt::ColorScheme::Dark) {
return true;
}
return false;
#else // less than Qt6.5.0
#elif defined(Q_OS_WIN32) && QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
return qApp->styleHints()->colorScheme() == Qt::ColorScheme::Dark;
#else // Windows less than Qt6.5.0 and ALL Linux
QPalette app_palette = qApp->palette();
bool isdark = app_palette.color(QPalette::Active,QPalette::WindowText).lightness() > 128;
return isdark;
#endif
#endif
}

bool Utility::IsWindowsSysDarkMode()
Expand Down

3 comments on commit cd4cad7

@dougmassay
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new colorScheme() == Qt::ColorScheme::Dark test doesn't appear to work consistently on all Linux dark themes.

Do you have any strong opinions on whether we should do this test for all platforms here, or in MainApplication like macOS is currently doing?

@kevinhendricks
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever you want to do is fine. After we get something working everyplace we can try to clean things up to share as much code as possible.

I did see a Qt issue about their test failing on some Linux boxes and someone recommended some code but I don't remember what exactly. Our version of dark or light detection has worked okay, or at least I thought it did.

@dougmassay
Copy link
Contributor Author

@dougmassay dougmassay commented on cd4cad7 May 3, 2024 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.