Windows 10 Dark Theme
-
wrote on 3 Apr 2019, 16:42 last edited by
Does Qt support the dark theme for Windows 10? It does on Mac OS and the preview in QtCreator on Windows is displayed using the system colors, but the compiled application displayed using the default or light theme.
-
Hi and welcome to the forums.
There is no official dark theme for compiled Qt apps.
However, this is pretty nice.
https://github.com/ColinDuquesnoy/QDarkStyleSheet
also
https://github.com/Jorgen-VikingGod/Qt-Frameless-Window-DarkStyleHowever, its based on stylesheets.
-
wrote on 3 Apr 2019, 21:39 last edited by
Thank you, this answers my question and helps!
-
wrote on 16 Apr 2019, 16:42 last edited by Carl_P
After trying the links above and a bit of Googling, the solution I ended up using was using QPalettes. This is very similar to the palettes used by Jorken-VikingGod in the link above. The advantage of this over the style sheets is that it it seemed to affect the layout of controls less since it uses the same controls. In case this is useful for anyone else, this code only uses the dark theme if compiling for Windows and the user is using the dark theme. If the user changes the theme while the program is running it does not change back to light, but this is still suitable for my needs. I just added the following to the main() function before showing the main window.
#ifdef Q_OS_WIN QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",QSettings::NativeFormat); if(settings.value("AppsUseLightTheme")==0){ qApp->setStyle(QStyleFactory::create("Fusion")); QPalette darkPalette; QColor darkColor = QColor(45,45,45); QColor disabledColor = QColor(127,127,127); darkPalette.setColor(QPalette::Window, darkColor); darkPalette.setColor(QPalette::WindowText, Qt::white); darkPalette.setColor(QPalette::Base, QColor(18,18,18)); darkPalette.setColor(QPalette::AlternateBase, darkColor); darkPalette.setColor(QPalette::ToolTipBase, Qt::white); darkPalette.setColor(QPalette::ToolTipText, Qt::white); darkPalette.setColor(QPalette::Text, Qt::white); darkPalette.setColor(QPalette::Disabled, QPalette::Text, disabledColor); darkPalette.setColor(QPalette::Button, darkColor); darkPalette.setColor(QPalette::ButtonText, Qt::white); darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, disabledColor); darkPalette.setColor(QPalette::BrightText, Qt::red); darkPalette.setColor(QPalette::Link, QColor(42, 130, 218)); darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218)); darkPalette.setColor(QPalette::HighlightedText, Qt::black); darkPalette.setColor(QPalette::Disabled, QPalette::HighlightedText, disabledColor); qApp->setPalette(darkPalette); qApp->setStyleSheet("QToolTip { color: #ffffff; background-color: #2a82da; border: 1px solid white; }"); } #endif
I also had to add #include <QStyleFactory> to main.cpp
-
After trying the links above and a bit of Googling, the solution I ended up using was using QPalettes. This is very similar to the palettes used by Jorken-VikingGod in the link above. The advantage of this over the style sheets is that it it seemed to affect the layout of controls less since it uses the same controls. In case this is useful for anyone else, this code only uses the dark theme if compiling for Windows and the user is using the dark theme. If the user changes the theme while the program is running it does not change back to light, but this is still suitable for my needs. I just added the following to the main() function before showing the main window.
#ifdef Q_OS_WIN QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",QSettings::NativeFormat); if(settings.value("AppsUseLightTheme")==0){ qApp->setStyle(QStyleFactory::create("Fusion")); QPalette darkPalette; QColor darkColor = QColor(45,45,45); QColor disabledColor = QColor(127,127,127); darkPalette.setColor(QPalette::Window, darkColor); darkPalette.setColor(QPalette::WindowText, Qt::white); darkPalette.setColor(QPalette::Base, QColor(18,18,18)); darkPalette.setColor(QPalette::AlternateBase, darkColor); darkPalette.setColor(QPalette::ToolTipBase, Qt::white); darkPalette.setColor(QPalette::ToolTipText, Qt::white); darkPalette.setColor(QPalette::Text, Qt::white); darkPalette.setColor(QPalette::Disabled, QPalette::Text, disabledColor); darkPalette.setColor(QPalette::Button, darkColor); darkPalette.setColor(QPalette::ButtonText, Qt::white); darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, disabledColor); darkPalette.setColor(QPalette::BrightText, Qt::red); darkPalette.setColor(QPalette::Link, QColor(42, 130, 218)); darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218)); darkPalette.setColor(QPalette::HighlightedText, Qt::black); darkPalette.setColor(QPalette::Disabled, QPalette::HighlightedText, disabledColor); qApp->setPalette(darkPalette); qApp->setStyleSheet("QToolTip { color: #ffffff; background-color: #2a82da; border: 1px solid white; }"); } #endif
I also had to add #include <QStyleFactory> to main.cpp
wrote on 14 Jan 2020, 15:03 last edited by Violet Giraffe@Carl_P, this is a great solution and really does work like charm, thanks for sharing! I couldn't find any missing bits that most of the dark stylesheets have.
The only nitpick I have is that the "Fusion" style doesn't really have the native look and feel. This was enough for me to refuse using this solution, but I love how concise and simple it is. Shame Qt still doesn't support the dark theme natively. -
After trying the links above and a bit of Googling, the solution I ended up using was using QPalettes. This is very similar to the palettes used by Jorken-VikingGod in the link above. The advantage of this over the style sheets is that it it seemed to affect the layout of controls less since it uses the same controls. In case this is useful for anyone else, this code only uses the dark theme if compiling for Windows and the user is using the dark theme. If the user changes the theme while the program is running it does not change back to light, but this is still suitable for my needs. I just added the following to the main() function before showing the main window.
#ifdef Q_OS_WIN QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",QSettings::NativeFormat); if(settings.value("AppsUseLightTheme")==0){ qApp->setStyle(QStyleFactory::create("Fusion")); QPalette darkPalette; QColor darkColor = QColor(45,45,45); QColor disabledColor = QColor(127,127,127); darkPalette.setColor(QPalette::Window, darkColor); darkPalette.setColor(QPalette::WindowText, Qt::white); darkPalette.setColor(QPalette::Base, QColor(18,18,18)); darkPalette.setColor(QPalette::AlternateBase, darkColor); darkPalette.setColor(QPalette::ToolTipBase, Qt::white); darkPalette.setColor(QPalette::ToolTipText, Qt::white); darkPalette.setColor(QPalette::Text, Qt::white); darkPalette.setColor(QPalette::Disabled, QPalette::Text, disabledColor); darkPalette.setColor(QPalette::Button, darkColor); darkPalette.setColor(QPalette::ButtonText, Qt::white); darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, disabledColor); darkPalette.setColor(QPalette::BrightText, Qt::red); darkPalette.setColor(QPalette::Link, QColor(42, 130, 218)); darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218)); darkPalette.setColor(QPalette::HighlightedText, Qt::black); darkPalette.setColor(QPalette::Disabled, QPalette::HighlightedText, disabledColor); qApp->setPalette(darkPalette); qApp->setStyleSheet("QToolTip { color: #ffffff; background-color: #2a82da; border: 1px solid white; }"); } #endif
I also had to add #include <QStyleFactory> to main.cpp
-
wrote on 15 Sept 2020, 21:18 last edited by
I just stumbled upon this, after successfully having adapted one of my projects to look good in dark mode on Linux/KDE and macOS. Is there anything new about this? Will Qt support Windows's dark mode, as it does on Linux and macOS without having to implement it manually?
-
Do you see any reason why the same build on the same qtlibs would have this dark theme working on some win10 and on some win10 it is still unchanged?
wrote on 24 Sept 2020, 17:17 last edited by Carl_P@Seb-Tur I don't know exactly. I think the thing I would look at is whether the AppsUseLightTheme setting is located in HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize in the version where the dark mode is not working. This can be found in regedit.msc
-
I just stumbled upon this, after successfully having adapted one of my projects to look good in dark mode on Linux/KDE and macOS. Is there anything new about this? Will Qt support Windows's dark mode, as it does on Linux and macOS without having to implement it manually?
wrote on 24 Sept 2020, 17:22 last edited by@l3u_ I think there may be some support for dark mode in Qt 5.15 or at least it may be coming. In the QGuiApplication documentation, there are platform specific command line options, this one looks promising:
darkmode=[1|2] controls how Qt responds to the activation of the Dark Mode for applications introduced in Windows 10 1903 (since Qt 5.15).
A value of 1 causes Qt to switch the window borders to black when Dark Mode for applications is activated and no High Contrast Theme is in use. This is intended for applications that implement their own theming.A value of 2 will in addition cause the Windows Vista style to be deactivated and switch to the Windows style using a simplified palette in dark mode. This is currently experimental pending the introduction of new style that properly adapts to dark mode.
-
@Seb-Tur I don't know exactly. I think the thing I would look at is whether the AppsUseLightTheme setting is located in HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize in the version where the dark mode is not working. This can be found in regedit.msc
-
wrote on 22 Jan 2021, 23:35 last edited by
@Carl_P 's solution combined with Qtimer it'll follows windows 10 mode changes immediately . Here is an example
-
@Carl_P 's solution combined with Qtimer it'll follows windows 10 mode changes immediately . Here is an example
wrote on 16 Mar 2021, 10:50 last edited by Romain CThis post is deleted! -
After trying the links above and a bit of Googling, the solution I ended up using was using QPalettes. This is very similar to the palettes used by Jorken-VikingGod in the link above. The advantage of this over the style sheets is that it it seemed to affect the layout of controls less since it uses the same controls. In case this is useful for anyone else, this code only uses the dark theme if compiling for Windows and the user is using the dark theme. If the user changes the theme while the program is running it does not change back to light, but this is still suitable for my needs. I just added the following to the main() function before showing the main window.
#ifdef Q_OS_WIN QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",QSettings::NativeFormat); if(settings.value("AppsUseLightTheme")==0){ qApp->setStyle(QStyleFactory::create("Fusion")); QPalette darkPalette; QColor darkColor = QColor(45,45,45); QColor disabledColor = QColor(127,127,127); darkPalette.setColor(QPalette::Window, darkColor); darkPalette.setColor(QPalette::WindowText, Qt::white); darkPalette.setColor(QPalette::Base, QColor(18,18,18)); darkPalette.setColor(QPalette::AlternateBase, darkColor); darkPalette.setColor(QPalette::ToolTipBase, Qt::white); darkPalette.setColor(QPalette::ToolTipText, Qt::white); darkPalette.setColor(QPalette::Text, Qt::white); darkPalette.setColor(QPalette::Disabled, QPalette::Text, disabledColor); darkPalette.setColor(QPalette::Button, darkColor); darkPalette.setColor(QPalette::ButtonText, Qt::white); darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, disabledColor); darkPalette.setColor(QPalette::BrightText, Qt::red); darkPalette.setColor(QPalette::Link, QColor(42, 130, 218)); darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218)); darkPalette.setColor(QPalette::HighlightedText, Qt::black); darkPalette.setColor(QPalette::Disabled, QPalette::HighlightedText, disabledColor); qApp->setPalette(darkPalette); qApp->setStyleSheet("QToolTip { color: #ffffff; background-color: #2a82da; border: 1px solid white; }"); } #endif
I also had to add #include <QStyleFactory> to main.cpp
wrote on 28 Apr 2021, 05:30 last edited byUsing Carl_P's solution works well for my application (Win10) on everything but QWizard and QWizardPage, how do I go about setting the colors on those as well?
-
@Carl_P 's solution combined with Qtimer it'll follows windows 10 mode changes immediately . Here is an example
wrote on 18 Nov 2021, 08:39 last edited byThis post is deleted!