After some research I found out, that Qt 5 now offers a so called Fusion theme which is desribed in one of their blog posts. I really like the theme with the black color configuration you can see in the last picture and I would like to use this in my application but it seems like this color scheme is forced by Unity/Gnome3 (looks like an Ubuntu window) so I am eager to knowing whether there is any available stylesheet or workaround to apply this dark version of the theme to an application.
If you have selected a system-wide option to prefer a dark theme, doc.qt.io follows that automatically. You can also toggle the theme on the website to override this default setting, by clicking the corresponding icon on the right side of the header.
To switch themes, select Edit > Preferences > Environment, and then select a theme in the Theme field. You can use the Qt Creator text and code editors with your favorite color scheme that defines how code elements are highlighted and which background color is used.
I'm sure you already found it, but, as TheBootroo said, Fusion theme is controlled by the color palette.
I've found a recreation of the palette here. It isn't complete at all!
qApp->setStyle(QStyleFactory::create("Fusion"));
QPalette p = qApp->palette();
p.setColor(QPalette::Window, QColor(53,53,53));
p.setColor(QPalette::Button, QColor(53,53,53));
p.setColor(QPalette::Highlight, QColor(142,45,197));
p.setColor(QPalette::ButtonText, QColor(255,255,255));
p.setColor(QPalette::WindowText, QColor(255,255,255));
qApp->setPalette(p);
Edit: I've created a gist so we can make it feature-complete.
This is my dark palette:
// set style
qApp->setStyle(QStyleFactory::create("Fusion"));
// increase font size for better reading
QFont defaultFont = QApplication::font();
defaultFont.setPointSize(defaultFont.pointSize()+2);
qApp->setFont(defaultFont);
// modify palette to dark
QPalette darkPalette;
darkPalette.setColor(QPalette::Window,QColor(53,53,53));
darkPalette.setColor(QPalette::WindowText,Qt::white);
darkPalette.setColor(QPalette::Disabled,QPalette::WindowText,QColor(127,127,127));
darkPalette.setColor(QPalette::Base,QColor(42,42,42));
darkPalette.setColor(QPalette::AlternateBase,QColor(66,66,66));
darkPalette.setColor(QPalette::ToolTipBase,Qt::white);
darkPalette.setColor(QPalette::ToolTipText,Qt::white);
darkPalette.setColor(QPalette::Text,Qt::white);
darkPalette.setColor(QPalette::Disabled,QPalette::Text,QColor(127,127,127));
darkPalette.setColor(QPalette::Dark,QColor(35,35,35));
darkPalette.setColor(QPalette::Shadow,QColor(20,20,20));
darkPalette.setColor(QPalette::Button,QColor(53,53,53));
darkPalette.setColor(QPalette::ButtonText,Qt::white);
darkPalette.setColor(QPalette::Disabled,QPalette::ButtonText,QColor(127,127,127));
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::Disabled,QPalette::Highlight,QColor(80,80,80));
darkPalette.setColor(QPalette::HighlightedText,Qt::white);
darkPalette.setColor(QPalette::Disabled,QPalette::HighlightedText,QColor(127,127,127));
qApp->setPalette(darkPalette);
Here you can find also a compelte example with frameless window and custom stylesheets to extend the dark palette: https://github.com/Jorgen-VikingGod/Qt-Frameless-Window-DarkStyle
AFAIK, the color of the Qt5 Fusion theme is entirely controlled by the color palette, which in its turn is controlled by the system theme. So on Ubuntu you'll get Orange colors, and blue on Windows...
So basically all you have to do is to use a tool or the QtProject.conf file to manually tune the color palette for the Qt5 apps, and don't forget to start your app with argument '-style fusion' because elsewere on ubuntu it's started with the GTk+ look emulation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With