Skip to content

Commit 7357121

Browse files
committed
Add dark mode checker depending on Qt version
1 parent 703da09 commit 7357121

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/clientdlg.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,7 +1479,18 @@ void CClientDlg::SetMixerBoardDeco ( const ERecorderState newRecorderState, cons
14791479
}
14801480
else
14811481
{
1482+
#if QT_VERSION >= QT_VERSION_CHECK( 6, 5, 0 )
1483+
// for Qt 6.5.0 or later, we use the inbuilt cross platform color scheme picker.
1484+
if ( QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark )
1485+
#else
1486+
#if defined( Q_OS_WINDOWS )
1487+
// for windows only, check lightnes as proposed in https://www.qt.io/blog/dark-mode-on-windows-11-with-qt-6.5
1488+
const QPalette defaultPalette;
1489+
if ( defaultPalette.color(QPalette::WindowText).lightness() > defaultPalette.color(QPalette::Window).lightness() )
1490+
#endif
14821491
if ( palette().color ( QPalette::Window ) == QColor::fromRgbF ( 0.196078, 0.196078, 0.196078, 1 ) )
1492+
#endif
1493+
14831494
{
14841495
// Dark mode on macOS/Linux needs a light color
14851496

src/clientdlg.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
#if QT_VERSION >= QT_VERSION_CHECK( 5, 6, 0 )
4343
# include <QVersionNumber>
4444
#endif
45+
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
46+
// for checking dark or light mode, we need to import more libraries
47+
# include <QGuiApplication>
48+
# include <QPalette>
49+
# include <QStyleHints>
50+
#endif
4551
#include "global.h"
4652
#include "util.h"
4753
#include "client.h"

0 commit comments

Comments
 (0)