Qt Forum

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

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    ListView: how to access a delegate

    QML and Qt Quick
    4
    5
    10369
    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.
    • E
      esaba last edited by

      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

      1 Reply Last reply Reply Quote 1
      • R
        richterX last edited by

        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@

        1 Reply Last reply Reply Quote 0
        • L
          luca last edited by

          [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
          @

          1 Reply Last reply Reply Quote 0
          • R
            richterX last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • S
              sraboisson last edited by

              Another alternative is to use

              @function change_color()
              {

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

              }@

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