Skip to content

Commit dd5a5b8

Browse files
committed
Add some magic to make title bar on Windows dark
Fix #5199
1 parent 6bfc0f3 commit dd5a5b8

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/app/app.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
#include "modules/value-editor/valueviewmodel.h"
4141
#include "qmlutils.h"
4242

43+
#ifdef Q_OS_WINDOWS
44+
#include <dwmapi.h>
45+
#endif
46+
4347
Application::Application(int& argc, char** argv)
4448
: QApplication(argc, argv),
4549
m_engine(this),
@@ -405,6 +409,26 @@ void Application::updatePalette()
405409
return;
406410
}
407411

408-
m_engine.rootObjects().at(0)->setProperty(
409-
"palette", QGuiApplication::palette());
412+
auto rootObject = m_engine.rootObjects().at(0);
413+
414+
rootObject->setProperty("palette", QGuiApplication::palette());
415+
416+
#ifdef Q_OS_WINDOWS
417+
if (!isDarkThemeEnabled()) return;
418+
419+
auto window = qobject_cast<QWindow*>(rootObject);
420+
421+
if (window) {
422+
auto winHwnd = reinterpret_cast<HWND>(window->winId());
423+
BOOL USE_DARK_MODE = true;
424+
BOOL SET_IMMERSIVE_DARK_MODE_SUCCESS = SUCCEEDED(DwmSetWindowAttribute(
425+
winHwnd, 20, &USE_DARK_MODE, sizeof(USE_DARK_MODE)));
426+
427+
if (SET_IMMERSIVE_DARK_MODE_SUCCESS) {
428+
// Dirty hack to re-draw window and apply darkmode color
429+
rootObject->setProperty("visible", false);
430+
rootObject->setProperty("visible", true);
431+
}
432+
}
433+
#endif
410434
}

src/resp.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ win32 {
9494

9595
release: DESTDIR = ./../bin/windows/release
9696
debug: DESTDIR = ./../bin/windows/debug
97+
98+
LIBS += -ldwmapi
9799
}
98100

99101
unix:macx { # OSX

0 commit comments

Comments
 (0)