Unsolved qtquickcontrols2.conf doesn't apply all settings
-
I'm trying to use the qtquickcontrols2.conf to define the global settings of my QML application.
Here my main.cpp file:#include <QGuiApplication> #include <QQmlApplicationEngine> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine qml(QUrl(QStringLiteral("qrc:/Main.qml"))); return app.exec(); }
Main.qml
import QtQuick 2.9 import QtQuick.Layouts 1.3 import QtQuick.Controls 2.2 import QtQuick.Controls.Material 2.2 ApplicationWindow { visible: true width: 1280 height: 800 Page { anchors.fill: parent header: TabBar { id: bar TabButton { text: qsTr("A") } TabButton { text: qsTr("B") } TabButton { text: qsTr("C") } } SwipeView { currentIndex: bar.currentIndex anchors.fill: parent Pane { Text { text: qsTr("1") } } Pane { Text { text: qsTr("2") } } Pane { Text { text: qsTr("3") } } } } }
qtquickcontrols2.conf added in the resources file:
[Controls] Style=Material [Material] Theme=Dark Accent=Purple Primary=BlueGrey [Material\Font] PixelSize=50
It actually applies only the Material 'Accent' properties. But neither 'Theme' nor 'PixelSize' properties are applied.
I'm running Qt5.9.1 under Windows 7 and to be sure whether they are supported I tried to put them inside my ApplicationWindow and they worked.It's the first time I wrote such a config file: is there any error in it?
-
- If I remember correctly, ToolBar is the only control that uses the Primary color. Not sure where you expect it to show up. :)
- Theme should work. Does the app run with the Material style at least, indicating that the .conf file is actually loaded?
- Support for specifying the default font in qtquickcontrols2.conf was added in Qt 5.10.
-
I've just updated to Qt 5.10.1 but:
- default font doesn't work, I had to use the old way:
auto font = app.font(); QFontInfo fi(font.defaultFamily()); font.setPixelSize(50); app.setFont(font);
- the Material theme is loaded but only partially: the Theme is not applied. Even if I set the Dark one it's still show the Light (or default?). Instead the Accent is working. I'm not talking about the Primary at all because I didn't know where it's used :)
-
But you get a dark background, right? Notice that the QML Text type is part of Qt Quick (core), meaning that it is not aware of the Qt Quick Controls 2 module. You may use the QML Label type to get a styled text label for Qt Quick Controls 2. What comes to the default font via qtquickcontrols2.conf, strange, because it works fine for me with 5.10.1. Did you run with the correct Qt Version (Kit)? :)
-
I didn't aware of that. I will try with the
Label
Component.
But I get a white background! Only the accent works from qtquickcontrols2.conf as said.