PDA

View Full Version : How to set a "dark color theme" for all widgets within the application ?



ralfwickum
23rd July 2015, 08:26
Hello,

my application is displayed currently in the standard grey color scheme. I would like to display my MainWindow and all its children and sub dialogs in a dark color theme... like: http://i.stack.imgur.com/t9o48.jpg

I currently use a Windows machine, but this setting should work on all OS. Is there a way for this?

Thanks in advance. Ralf

west
23rd July 2015, 08:30
Use Qt Style Sheet.
Examples:
https://github.com/EClaesson/QTDark
https://github.com/ColinDuquesnoy/QDarkStyleSheet

osirisgothra
13th April 2022, 18:26
poke, poke...


Use Qt Style Sheet.
Examples:
https://github.com/EClaesson/QTDark
https://github.com/ColinDuquesnoy/QDarkStyleSheet

Just a quick note on any survivors that made it this far (and want to get dark, quickly):
You do not have to do all that if you want just the background and foreground colors reversed (and * is not a good idea if you want to change attributes like 'border' which forces stuff that didn't have a border before to now have one). It's best to just put a style on QWidget and use 'border-color', that way if there is no border, you are not adding one in a place where it would look weird, like around every label for example. Also, programmers often do not measure a border or any other attribute that wasn't supposed to be there in the first place, when placing their widgets programmatically, though that is actually a no-no because you have to assume someone might use the -stylesheet command unless you block it explicitly when QApplication is getting underway, but that's a trickery subject for another time! Now, remember to always delegate whatever you can, whenever you can. It will save you time in the long run!
You should put in a style like '-style 'fusion' and then specify a minimal dark/light theme that modifies QWidget, since most widgets that you'll want to change derive from it. Also don't modify 'background', but rather 'background-color' for the same reasons as border, unless you don't want the program to show any background images at all. At this point your should have very few classes to go back and "fix" (like making the cursor transparent, for one). This works in Linux, Windows, Mac, whatever, because of the "platforminess" of the Qt framework. Last thing, you might want to restrict changes from going into QWebANYTHING because that is a mess you don't want, believe me. Well, have fun!