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. ListView: how to access a delegate
QtWS25 Last Chance

ListView: how to access a delegate

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 4 Posters 10.7k 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.
  • E Offline
    E Offline
    esaba
    wrote on last edited by
    #1

    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
    1
    • R Offline
      R Offline
      richterX
      wrote on last edited by
      #2

      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
      0
      • L Offline
        L Offline
        luca
        wrote on last edited by
        #3

        [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
        0
        • R Offline
          R Offline
          richterX
          wrote on last edited by
          #4

          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
          0
          • S Offline
            S Offline
            sraboisson
            wrote on last edited by
            #5

            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
            0

            • Login

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