Possible to get style name in QML?
-
Hi all -
Actually, I know it's possible; I'm just looking for the easiest way to do it.
Suppose I have an application that needs to run on multiple platforms, with different styles. In my main.cpp, I do this:
QString qmlStyle = (platform == "android") ? "Material" : "Fusion"; QQuickStyle::setStyle(qmlStyle);
So, I know I can do this in a class, and declare a Q_PROPERTY, and all that stuff, but...I'm guessing there's an easier way to retrieve this stylename?
I want to do this, so my QML can do something like this:
TabBar { property string styleName // gotten from somewhere Component.onCompleted: { if (styleName == "Material") { Material.accent = Colors.primaryPurple } else if (styleName == "Fusion") { Fusion.accent = Colors.primaryPurple } } }
which does seem like a hack, so if there's a better way to do this, I'm all ears.
Thanks...
-
I would suggest a simple contextProperty:
QString qmlStyle = (platform == "android") ? "Material" : "Fusion"; QQuickStyle::setStyle(qmlStyle); QQmlApplicationEngine engine; engine.rootContext()->setContextProperty("StyleName", qmlStyle);
-
I would suggest a simple contextProperty:
QString qmlStyle = (platform == "android") ? "Material" : "Fusion"; QQuickStyle::setStyle(qmlStyle); QQmlApplicationEngine engine; engine.rootContext()->setContextProperty("StyleName", qmlStyle);