Reputation: 23
I want to isolate the style of my components in a file like "ComponentStyle.qml" (Qt5)
Item {
id:root
Component {
id: touchStyle
ButtonStyle {
....
}
}
Component {
id: switchStyle
SwitchStyle {
....
}
}
}
So, in my main.qml, I want to use the style like :
...
Button {
style: touchStyle
text: "Press me"
width: parent.width
anchors.horizontalCenter: parent.horizontalCenter
}
But, it wont work ! I have some errors :
file:///C:/Qt/5.2.0/msvc2012/qml/QtQuick/Controls/Switch.qml:133: TypeError: Type error file:///C:/Qt/5.2.0/msvc2012/qml/QtQuick/Controls/Button.qml:92: TypeError: Cannot read property 'width' of null
main.qml:60: ReferenceError: touchStyle is not defined*
Is someone can help me ? Thanks a lot !
Upvotes: 2
Views: 3110
Reputation: 2829
Unfortunately I think I would have to see more of your ComponentStyle.qml but I think you're missing properties.
You should use these two links to get an overall idea of how to format you code for themes and styles.
Styling - Has great examples on styling text and buttons very applicable to your case.
QmlStyling - Lists different approaches and techniques for implementing styling.
I hope that helps.
Upvotes: 1