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. Get Repeater's child
Forum Updated to NodeBB v4.3 + New Features

Get Repeater's child

Scheduled Pinned Locked Moved QML and Qt Quick
13 Posts 4 Posters 11.4k Views 1 Watching
  • 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.
  • I Offline
    I Offline
    ixSci
    wrote on last edited by
    #1

    Hello folks, I'm just wondering how I can change the visual element which has been created by the Repeater or other "Positioner" elements. I have the following QML:
    @Repeater{
    model: buttunGroup.buttonList
    RadioButton{
    title: buttonText
    }
    }@
    After it has been created I want to change some property of one of my "RadioButton" elements but I find no way to accomplish that. I've found the children property but have no clue how to dissect a list I retrieved from that property.
    Is there a way to do that?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      Kxyu
      wrote on last edited by
      #2

      you can make an array in .js file and add all children in it using onCompleted signal

      1 Reply Last reply
      0
      • I Offline
        I Offline
        ixSci
        wrote on last edited by
        #3

        Kxyu, thanks for the answer!
        No options to achieve it without wielding JS?
        It is not that I 've something against JS. I just want to have a pure QML solution for this, if any.
        There is no way to acquire children from the list, is there?

        1 Reply Last reply
        0
        • K Offline
          K Offline
          Kxyu
          wrote on last edited by
          #4

          you can, actually I figured it out) i found the following string in Repeater description:
          Items instantiated by the Repeater are inserted, in order, as children of the Repeater's parent

          So you can access the children like this:

          @import Qt 4.7

          Rectangle {
          id: screen
          width: 1024
          height: 600

          Row{
          id:container
          Repeater{
          model:3
          delegate:Rectangle{
          width:100
          height:100
          color:"red"
          }

          }
          }

          Component.onCompleted:container.children[1].color="black"

          }
          @

          it works!

          1 Reply Last reply
          0
          • I Offline
            I Offline
            ixSci
            wrote on last edited by
            #5

            Kxyu, it is exactly what I've searched for. Thank you for the solution.
            Though I don't understand why the parent item doesn't keep its children amount. Maybe it should? It seems a bit awkward to retrieve children from a Row and get children number from a Repeater :)

            Nevertheless, the question is answered.

            1 Reply Last reply
            0
            • K Offline
              K Offline
              Kxyu
              wrote on last edited by
              #6

              Well it keeps, as children is a List, and List does. But as far as I understand in QML it works like javascript array, so you can use it's length property. I don't know why, but it gives amount+1, still you can use it

              1 Reply Last reply
              0
              • X Offline
                X Offline
                xsacha
                wrote on last edited by
                #7

                Well the children array is 0-index. So 0 is the first child. However, a length property will be 1-index.
                If you've already accounted for this, it could be that the 0th child is pre-populated (some hidden child?). I haven't tested this though.

                • Sacha
                1 Reply Last reply
                0
                • I Offline
                  I Offline
                  ixSci
                  wrote on last edited by
                  #8

                  [quote author="Kxyu" date="1293186164"]Well it keeps, as children is a List, and List does. But as far as I understand in QML it works like javascript array, so you can use it's length property. I don't know why, but it gives amount+1, still you can use it
                  [/quote]
                  Interesting property it should be documented I believe. Because I didn't find any mentions about it neither in documentation nor in the IntelliSense in QtCreator.

                  1 Reply Last reply
                  0
                  • I Offline
                    I Offline
                    ixSci
                    wrote on last edited by
                    #9

                    Just tested it: a Repeater is the rightful child of an Item that is why you have amount + 1 result. If you exclude Repeater from the item you will have an actual amount.

                    1 Reply Last reply
                    0
                    • X Offline
                      X Offline
                      xsacha
                      wrote on last edited by
                      #10

                      IntelliSense needs some updates. It's not mentioned in documentation probably because it isn't related to QML. Just as the Math.functions aren't mentioned. Basically, javascript works in QML.

                      • Sacha
                      1 Reply Last reply
                      0
                      • I Offline
                        I Offline
                        ixSci
                        wrote on last edited by
                        #11

                        But if the QML list is nothing more than JS list why there is not a single word about it? How can user find that he can use length property, for example, if he has no clue about a nature of a QML list?

                        1 Reply Last reply
                        0
                        • K Offline
                          K Offline
                          Kxyu
                          wrote on last edited by
                          #12

                          [quote author="xsacha" date="1293190186"]IntelliSense needs some updates. It's not mentioned in documentation probably because it isn't related to QML. Just as the Math.functions aren't mentioned. Basically, javascript works in QML.[/quote]

                          well, that's correct, but I think it would be better, if list in QML had all QList members and worked the same way, not like javascript array

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            arunasank
                            wrote on last edited by
                            #13

                            Thank you for this answer, was very helpful!

                            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