ListElement: cannot use script for property value
Unsolved
QML and Qt Quick
-
Hello,
I am trying to use a value stored by property inside a list element and i am facing the following error "ListElement: cannot use script for property value" when googled i got to know that this is a limitation in Qt itself.
one.qml
property var themeColour : (themes.name === 'day') ? 'black' : 'white' ListModel{ id:btnModel ListElement {name: "T"; iconColour: themeColour} //error : ListElement: cannot use script for property value ListElement {name: "CI"; iconColour: themeColour} ListElement {name: "S"; iconColour: themeColour} ListElement {name: "S"; iconColour: themeColour} }
Two.qml
Repeater { id:btnsReapeter model: btnModel Button { text: qsTr(name) implicitWidth: 162 implicitHeight: 162 iconColor: iconColour // i wanted to use iconColour from list element here onClicked: gridBtnClicked(name, index) } }
I read and tried various solutions that i came across from in google, but none of them was working, can some one help me suggesting a workaround for the same.
Thanks in advance !!
Regard's,
Rohith -
hi @Rohith
you can remove the iconColour from your model and simply assign it directlyButton { text: qsTr(name) implicitWidth: 162 implicitHeight: 162 iconColor: (themes.name === 'day') ? 'black' : 'white' onClicked: gridBtnClicked(name, index) }
or put all your colors in an array then
iconColor: myArrayOfColors[index]
or if your model is too complicated you can use a c++ model and expose it to qml