深色主题不适用于标题栏

Lin*_*oca 6 c++ qt

我已经在我的应用程序中应用了深色样式,直到那时都很好,我的问题是为什么该样式没有应用于我的应用程序的标题栏,以及在我的应用程序中打开的其余表单,如您所见,它保持白色并且看起来很糟糕,任何建议将不胜感激。

在此输入图像描述

#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();
}
Run Code Online (Sandbox Code Playgroud)

我从这里得到了主题。 https://github.com/ColinDuquesnoy/QDarkStyleSheet

Nik*_*lay 4

[适用于 Qt 6.2.2,不确定 Qt5]

在与可执行文件相同的文件夹中可能有一个配置文件 qt.conf 。如果不存在,则创建。并添加行

[Platforms]
WindowsArguments = darkmode=1
Run Code Online (Sandbox Code Playgroud)

darkmode=2如果您还想即时更改标题栏颜色,请使用。

更新:该方案在 Qt 6.5 中完全改变。现在已有详细记录,请参阅https://www.qt.io/blog/dark-mode-on-windows-11-with-qt-6.5