I am currently trying to extend our application with different style. For each style I have a separate qml file with e.g. color definitions. StyleA.qml:
import QtQuick 2.0
QtObject {
property color textColorStandard: 'black'
...
}
In my main.qml I would like to load the right qml file, based on a software property:
import QtQuick 2.0
Item {
id: mainPanel
....
Loader {
id: myDynamicStyle
source: Property.UseThemeA? "StyleA.qml" : "StyleB.qml"
}
...
Item {
id: BackGround
color: myDynamicStyle.textColorStandard
}
}
unfortunately this approach does not work. Is there any other/better way to accomplish styling?
thanks, michael
Using things loaded in Loader is badly typed, I would rather :
First, create a common ancestor Component for all my styles, e.g :
Next, derivate it to create custom styles, e.g :
Then use a strongly typed property in my object that must use a style, e.g:
That way, there are multiple advantages :
Did you try using this instead? The loaded object is store into the item property of the loader and no in the loader directly.