Activate custom stylesheet to mimic dark mode on Qt versions those do not support native dark mode.

This commit is contained in:
Roman Telezhynskyi 2023-08-13 19:58:58 +03:00
parent 20117e78a2
commit ae549bf948

View File

@ -217,13 +217,60 @@ void ActivateCustomDarkTheme()
} }
} }
//---------------------------------------------------------------------------------------------------------------------
#if defined(Q_OS_WIN)
void ActivateDefaultThemeWin()
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
qApp->setStyleSheet(QString()); // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast)
#else
if (VTheme::IsInDarkTheme())
{
ActivateCustomDarkTheme();
}
else
{
ActivateCustomLightTheme();
}
#endif // QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
}
#endif // defined(Q_OS_WIN)
//---------------------------------------------------------------------------------------------------------------------
#if defined(Q_OS_MACX)
void ActivateDefaultThemeMac()
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
qApp->setStyleSheet(QString()); // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast)
#else
if (VTheme::IsInDarkTheme())
{
ActivateCustomDarkTheme();
}
else
{
ActivateCustomLightTheme();
}
#endif // QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
}
#endif // defined(Q_OS_MACX)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void ActivateDefaultTheme() void ActivateDefaultTheme()
{ {
qApp->setStyleSheet(QString()); // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast) #if defined(Q_OS_WIN)
ActivateDefaultThemeWin();
#if defined(Q_OS_MACX) #elif defined(Q_OS_MACX)
NSMacSetToAutoTheme(); ActivateDefaultThemeMac();
#else
if (VTheme::IsInDarkTheme())
{
ActivateCustomDarkTheme();
}
else
{
ActivateCustomLightTheme();
}
#endif #endif
} }
@ -466,10 +513,6 @@ void VTheme::InitThemeMode()
{ {
ActivateCustomDarkTheme(); ActivateCustomDarkTheme();
} }
else
{
ActivateCustomLightTheme();
}
} }
} }
} }