Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved ListElement: cannot use script for property value

    QML and Qt Quick
    listelement property
    2
    2
    423
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      Rohith last edited by

      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

      ODБOï 1 Reply Last reply Reply Quote 0
      • ODБOï
        ODБOï @Rohith last edited by ODБOï

        hi @Rohith
        you can remove the iconColour from your model and simply assign it directly

                    Button {
                        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

        1 Reply Last reply Reply Quote 0
        • First post
          Last post