6

I have applied a dark style to my application, so good until then, my question is why the style is not applied to the title bar of my application, and the rest of the forms that open in me application, as you can see, it stays white and looks very bad, any suggestions would be appreciated.

enter image description here

#include "mainwindow.h"

#include <QApplication>
#include <QFile>
#include <QTextStream>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QFile f(":/qdarkstyle/style.qss");
    f.open(QIODevice::ReadOnly|QIODevice::Text);
    QTextStream ts(&f);
    a.setStyleSheet(ts.readAll());

    MainWindow w;
    w.show();
    return a.exec();
}

I got the subject from here. https://github.com/ColinDuquesnoy/QDarkStyleSheet

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • I think unless you draw the title bars yourself you'll always have the system colours though this might help: https://stackoverflow.com/questions/57124243/winforms-dark-title-bar-on-windows-10 – Alan Birtles Jan 23 '21 at 18:02
  • The Windows API makes it very difficult to theme some parts of a window, I think scroll bars are even worse. Maybe the Qt developers decided it wasn't worth the trouble? – Mark Ransom Jan 23 '21 at 18:09
  • ok, I understand, thank you. – Lincoln Ingaroca Jan 24 '21 at 00:06

1 Answers1

4

[Works on Qt 6.2.2, not sure about Qt5]

There might be a configuration file qt.conf in the same folder as your executable file. If it does not exist, create. And add the lines

[Platforms]
WindowsArguments = darkmode=1

Use darkmode=2 if you also want to change the title bar colour on the fly.

Update: the scheme is completely changed in Qt 6.5. And it is now well-documented, see https://www.qt.io/blog/dark-mode-on-windows-11-with-qt-6.5.

Nikolay
  • 168
  • 1
  • 9
  • Works on Qt 5.11 too – Michael Galuza May 16 '22 at 06:33
  • I just tried this approach but can't get it to work somehow (my app is using Qt 5.15.2 at the moment). Is there maybe something else I need to do to make this apply a dark title bar? How does the resulting bar look like on systems where it works? – codeling Jun 09 '22 at 06:05
  • Figured it out - the "default app mode" for colors in the Windows settings also has to be set to "Dark" in order for the `darkmode` setting in qt.conf to be effective. – codeling Jun 09 '22 at 06:54