Search code examples
qtqmlqt5qtquick2qstylesheet

How to load a stylesheet while using QQmlApplicationEngine


I am currently trying to load a stylesheet for a simple Qt5 application. Therefore I use the following code:

QApplication app(argc, argv);

QFile styleFile("./css/style.qss");
styleFile.open(QFile::ReadOnly);
QString stylesheet = QLatin1String(styleFile.readAll());
app.setStyleSheet(stylesheet);

QQmlApplicationEngine engine;
engine.load("./qml/main.qml");

app.exec();

However, the stylesheet is loaded correctly, but not applied. How do I have to change the above code, to get it working?


Solution

  • QML itself doesn't support stylesheets as QWidget does. But you still can customize your app in several ways. See here for more details.

    As a workaround you can use some Third-party plugins, for example Ableton.stylesheets