ListView: how to access a delegate



  • Hi,
    How is possible to send a signal to a ListView Element?

    I know it is possibile for the currentItem of a ListView, but I haven't found the documentation for non-current elements

    Thanks



  • If you have the id for the list model you should be able to index into the desired element and do stuff with the properties. If you can access the properties or functions you can subscribe the element to your signal or just call a function.

    @myListModel.children[indexIwant].someProperty@



  • [quote author="richterX" date="1331056296"]If you have the id for the list model you should be able to index into the desired element and do stuff with the properties. If you can access the properties or functions you can subscribe the element to your signal or just call a function.

    @myListModel.children[indexIwant].someProperty@

    [/quote]

    Hi, I need to access a property of an item of a ListView as follow:
    @
    function change_color()
    {

       for(var i=0; i<MyListView.count; i++)
      {
         MyListView.children[i].my_text.color = "red"
      }
    

    }
    @

    but I get the following error:
    @
    TypeError: Result of expression 'MyListView.children[i]' [undefined] is not an object
    @



  • To set a property in a list view where you use a delegate you should probably use setProperty(). Modifying your example, it would be:

    @function change_color()
    {

       for(var i=0; i<MyListView.count; i++)
      {
         MyListView.model.setProperty(i, "my_text.color", "red");
      }
    

    }@

    I'm fairly certain the property name can have "."s in it. If not, modify your type to have a direct alias property to the the color of its text.



  • Another alternative is to use

    @function change_color()
    {

      for(var i=0; i<MyListView.count; i++)
      {
         MyListView.model.get(i).my_text.color = "red";
      }
    

    }@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.