How to set a color scheme for a QMainWindow?
-
In Qt 6.8.2 Desktop application that runs on Ubuntu 24.10, I have this main.cpp:
#include "mainwindow.h" #include <QStyleHints> #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); QGuiApplication::styleHints()->setColorScheme(Qt::ColorScheme::Light); MainWindow w; w.show(); return a.exec(); }
but this is the actual appearance:
so it still follows the system theme regardless the explictly setting of the light color scheme.
By the way if I write:QGuiApplication::styleHints()->setColorScheme(Qt::ColorScheme::Light); qDebug() << QGuiApplication::styleHints()->colorScheme();
it outputs:
Qt::ColorScheme::Dark
It seems it silently ignores the request.
Is there anything else I should add to force the desired color scheme? -
From a quick look at the code, the platform plugins currently don't handle that request yet.
-
Hi,
Which desktop environment are you using ?
-
From a quick look at the code, the platform plugins currently don't handle that request yet.
-
@SGaist Got it. Out of curiosity, I RTFM but I wasn't able to find this information. Actually, the docs say:
Sets the color scheme used by the application to an explicit scheme, or revert to the system's current color scheme if scheme is Qt::ColorScheme::Unknown.
There is no mention that this function is not implemented yet.
Are you saying there is no way to know this besides inspect the source code, aren't you? -
-
I would expect to have somewhere a list of the platform where the value is in use. I haven't checked all the platform backends. Just the Linux ones where I haven't seen the value in use.