Skip to content

Commit

Permalink
fix: disable Qt6.7's dark mode and force Fusion style no matter what (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
shenlebantongying authored May 13, 2024
1 parent 685b2ec commit e7c5967
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include "gddebug.hh"
#include <QMutex>
#include <QStyleFactory>

#if defined( USE_BREAKPAD )
#if defined( Q_OS_MAC )
Expand Down Expand Up @@ -351,6 +352,8 @@ int main( int argc, char ** argv )
freopen( "CON", "w", stderr );
}

qputenv( "QT_QPA_PLATFORM", "windows:darkmode=1" );

#endif


Expand All @@ -368,6 +371,12 @@ int main( int argc, char ** argv )
QHotkeyApplication::setOrganizationDomain( "https://github.com/xiaoyifang/goldendict-ng" );
QHotkeyApplication::setWindowIcon( QIcon( ":/icons/programicon.png" ) );

#ifdef Q_OS_WIN
// TODO: Force fusion because Qt6.7's "ModernStyle"'s dark theme have problems, need to test / reconsider in future
QHotkeyApplication::setStyle( QStyleFactory::create( "Fusion" ) );
#endif


#if defined( USE_BREAKPAD )
QString appDirPath = Config::getConfigDir() + "crash";

Expand Down
3 changes: 2 additions & 1 deletion src/stylesheets/qt-lingoes-blue.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
MainWindow {
MainWindow,
QToolBar {
background-color: #cfddf0;
}

Expand Down
5 changes: 1 addition & 4 deletions src/ui/mainwindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1305,9 +1305,7 @@ void MainWindow::updateAppearances( QString const & addonStyle,
#ifdef Q_OS_WIN32
if ( darkMode ) {
//https://forum.qt.io/topic/101391/windows-10-dark-theme
#ifdef Q_OS_WIN32
qApp->setStyle( QStyleFactory::create( "Fusion" ) );
#endif

QPalette darkPalette;
QColor darkColor = QColor( 45, 45, 45 );
QColor disabledColor = QColor( 127, 127, 127 );
Expand All @@ -1334,7 +1332,6 @@ void MainWindow::updateAppearances( QString const & addonStyle,
qApp->setPalette( darkPalette );
}
else {
qApp->setStyle( new QProxyStyle() );
qApp->setPalette( QPalette() );
}
#endif
Expand Down

0 comments on commit e7c5967

Please sign in to comment.