From a3386f16054e833ddf108a032c027476833c6fc0 Mon Sep 17 00:00:00 2001 From: Nicholas Omann Date: Sat, 17 Dec 2022 00:00:36 +0000 Subject: [PATCH] Enable Support for Dark Theme for Titlebar in Windows When using the windows dark theme it's annoying to have white titlebars on some apps. I noticed that this app which and I would like to use on Windows but the lack of dark theme on the titlebar makes it not fit in well. I did some research on this and found that the best way to set it seems to be using the darkmode toggle on the platform. That can be set as a parameter or environment variable. This seems to be the easiest way to set it. I tested this locally on a Win11 VM and it looks to work the same as setting -platform windows:darkmode=1 or setting QT_QPA_PLATFORM=windows:darkmode=1. Note this does need to be set before the QApplication is originally created and so I think it has to be done per app to work. If I missed some other way to set this that would be better I would be interested to know more. QT Docs: https://doc.qt.io/qt-5/qguiapplication.html#platform-specific-arguments (cherry picked from commit f0e3581babecb34dd3ae4b226e4ad6b51f336331) --- shell/main.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/shell/main.cpp b/shell/main.cpp index ea251ee52..870bd2468 100644 --- a/shell/main.cpp +++ b/shell/main.cpp @@ -27,6 +27,15 @@ int main(int argc, char **argv) { + /** + * enable dark mode for title bar on Windows + */ +#if defined(Q_OS_WIN) + if (!qEnvironmentVariableIsSet("QT_QPA_PLATFORM")) { + qputenv("QT_QPA_PLATFORM", "windows:darkmode=1"); + } +#endif + /** * enable high dpi support */