fix default GUI theme application on the fly

This commit is contained in:
Garux 2023-07-24 15:43:36 +06:00
parent 4e1c8adbff
commit 32c4ded9d2

View File

@ -19,7 +19,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include <QStyleFactory> #include <QStyle>
#include <QApplication> #include <QApplication>
#include <QMenu> #include <QMenu>
#include <QActionGroup> #include <QActionGroup>
@ -45,7 +45,13 @@ void theme_set( ETheme theme ){
// QSettings settings( "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", QSettings::NativeFormat ); // QSettings settings( "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", QSettings::NativeFormat );
// if( settings.value( "AppsUseLightTheme" ) == 0 ) // if( settings.value( "AppsUseLightTheme" ) == 0 )
#endif #endif
static const QPalette default_palette = qApp->palette(); static struct
{
bool is1stThemeApplication = true; // guard to not apply possibly wrong defaults while app is started with Default theme
const QPalette palette = qApp->palette();
const QString style = qApp->style()->objectName();
}
defaults;
const char* sheet = R"( const char* sheet = R"(
QToolTip { QToolTip {
@ -136,10 +142,14 @@ void theme_set( ETheme theme ){
)"; )";
if( theme == ETheme::Default ){ if( theme == ETheme::Default ){
qApp->setPalette( default_palette ); if( !defaults.is1stThemeApplication ){
qApp->setPalette( defaults.palette );
qApp->setStyleSheet( "" );
qApp->setStyle( defaults.style );
}
} }
else if( theme == ETheme::Dark ){ else if( theme == ETheme::Dark ){
qApp->setStyle( QStyleFactory::create( "Fusion" ) ); qApp->setStyle( "Fusion" );
QPalette darkPalette; QPalette darkPalette;
QColor darkColor = QColor( 83, 84, 81 ); QColor darkColor = QColor( 83, 84, 81 );
QColor disabledColor = QColor( 127, 127, 127 ); QColor disabledColor = QColor( 127, 127, 127 );
@ -168,7 +178,7 @@ void theme_set( ETheme theme ){
qApp->setStyleSheet( sheet ); qApp->setStyleSheet( sheet );
} }
else if( theme == ETheme::Darker ){ else if( theme == ETheme::Darker ){
qApp->setStyle( QStyleFactory::create( "Fusion" ) ); qApp->setStyle( "Fusion" );
QPalette darkPalette; QPalette darkPalette;
QColor darkColor = QColor( 45, 45, 45 ); QColor darkColor = QColor( 45, 45, 45 );
QColor disabledColor = QColor( 127, 127, 127 ); QColor disabledColor = QColor( 127, 127, 127 );
@ -194,6 +204,8 @@ void theme_set( ETheme theme ){
qApp->setStyleSheet( sheet ); qApp->setStyleSheet( sheet );
} }
defaults.is1stThemeApplication = false;
} }
void theme_contruct_menu( class QMenu *menu ){ void theme_contruct_menu( class QMenu *menu ){