Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. ListElement: cannot use script for property value
QtWS25 Last Chance

ListElement: cannot use script for property value

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
listelementproperty
2 Posts 2 Posters 2.6k Views
  • 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 Offline
    R Offline
    Rohith
    wrote on last edited by
    #1

    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ïO 1 Reply Last reply
    0
    • R Rohith

      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ïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by ODБOï
      #2

      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
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved