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. Change property of all items in a Repeater at once?
Forum Updated to NodeBB v4.3 + New Features

Change property of all items in a Repeater at once?

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 2.1k 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.
  • G Offline
    G Offline
    ggwolf
    wrote on last edited by
    #1

    I want blanket commands that modify a property of every item of the repeater. right now I have this javascript function that does the job:

    @ function disable() {
    for (var i = 0; i < theRepeater.model; i++) {
    theRepeater.itemAt(i).state = "disabled"
    }
    }@

    But I am hoping for a single command that can change the state of every item in the repeater to disabled

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      Create a property variable , and then bind that property to the state of the Item and then when you change that property variable the state of each item changes as well

      157

      1 Reply Last reply
      0
      • G Offline
        G Offline
        ggwolf
        wrote on last edited by
        #3

        [quote author="p3c0" date="1406786774"]Hi,

        Create a property variable , and then bind that property to the state of the Item and then when you change that property variable the state of each item changes as well[/quote]

        Could you provide an example? I'm not sure what you mean by a property that is bound to the state... isnt that what the state property is for? and where should i be creating this property variable?

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          Sure here it is,
          @
          Item {
          width: 400
          height: 200

          property string currentState: ""
          
          Repeater {
              id: repeater
              model: 5
              Rectangle {
                  id: rect
                  x: index * 50
                  y: 0
                  width: 50
                  height: 50
                  color: '#'+Math.floor(Math.random()*16777215).toString(16)
                  state: currentState
          
                  states: State {
                      name: "moved";
                      PropertyChanges { target: rect; y: 50 }
                  }
          
                  transitions: Transition {
                      NumberAnimation { properties: "y"; easing.type: Easing.InOutQuad }
                  }
          
              }
          }
          
          Button {
              text: "Click"
              y: 200-50
              width: 80
              height: 50
              onClicked: { currentState="moved" }
          }
          

          }
          @

          Now here the property variable currentState is binded to state property of each Rectangle. And on click of button we assign a new value to the property currentState and thus on that change the state of each Rectangle gets affected too.
          Hope this is what you expect ...

          157

          1 Reply Last reply
          0
          • G Offline
            G Offline
            ggwolf
            wrote on last edited by
            #5

            This is an interesting example of QML usage, thanks. I can't use currently because each rectangle's state gets overridden and becomes individual so I have to go back through each one and reset it somehow. I want each item in the repeater to be independent, except in this one case.

            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