Dark Mode for QT Application

With dark mode becoming quite fast the default setup for many, I figured having it in the new QText wouldn't hurt. And with QT it's easy - surprisingly so. Just start with a good style (i.e. Fusion) and adjust its palette. And that's all it took.

Code
qApp->setStyle(QStyleFactory::create("Fusion"));

QPalette newPalette;
newPalette.setColor(QPalette::Window, QColor( 37, 37, 37));
newPalette.setColor(QPalette::WindowText, QColor(212, 212, 212));
newPalette.setColor(QPalette::Base, QColor( 60, 60, 60));
newPalette.setColor(QPalette::AlternateBase, QColor( 45, 45, 45));
newPalette.setColor(QPalette::PlaceholderText, QColor(127, 127, 127));
newPalette.setColor(QPalette::Text, QColor(212, 212, 212));
newPalette.setColor(QPalette::Button, QColor( 45, 45, 45));
newPalette.setColor(QPalette::ButtonText, QColor(212, 212, 212));
newPalette.setColor(QPalette::BrightText, QColor(240, 240, 240));
newPalette.setColor(QPalette::Highlight, QColor( 38, 79, 120));
newPalette.setColor(QPalette::HighlightedText, QColor(240, 240, 240));

newPalette.setColor(QPalette::Light, QColor( 60, 60, 60));
newPalette.setColor(QPalette::Midlight, QColor( 52, 52, 52));
newPalette.setColor(QPalette::Dark, QColor( 30, 30, 30) );
newPalette.setColor(QPalette::Mid, QColor( 37, 37, 37));
newPalette.setColor(QPalette::Shadow, QColor( 0, 0, 0));

newPalette.setColor(QPalette::Disabled, QPalette::Text, QColor(127, 127, 127));

qApp->setPalette(newPalette);

PS: Ok, chances are that you will need another iconset but that's the story for some other time.

One thought to “Dark Mode for QT Application”

Leave a Reply

Your email address will not be published. Required fields are marked *