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 elements to give them a specific script
Forum Updated to NodeBB v4.3 + New Features

Get repeater elements to give them a specific script

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 3 Posters 417 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.
  • D Offline
    D Offline
    DavidM29
    wrote on last edited by
    #1

    I have a few rectangles that I created with a repeater. Those rectangle are going to use a mouse area to add actions to each one. But my problem is that I don't know how to give each one a different action ( call different method, or call with specific properties...)
    Does anybody can help me with this ?

    Thank you in advance

    1 Reply Last reply
    0
    • GPBetaG Offline
      GPBetaG Offline
      GPBeta
      wrote on last edited by
      #2

      Hi, do you mean something like this:

      Column {
          anchors.centerIn: parent
      
          spacing: 4
      
          Repeater {
              model: 4
      
              Rectangle {
                  id: rect
      
                  width: 100
                  height: 100
                  color: "black"
      
                  property var func
      
                  MouseArea {
                      anchors.fill: parent
                      onClicked: rect.func()
                  }
              }
      
              onItemAdded: {
                  if (index % 2)
                      item.func = function () { console.log("function 1 called."); }
                  else
                      item.func = function () { console.log("function 2 called."); }
              }
          }
      }
      

      \BAKA BAKA/

      1 Reply Last reply
      1
      • ODБOïO Offline
        ODБOïO Offline
        ODБOï
        wrote on last edited by
        #3

        hi @DavidM29,
        On way to do that is passing the index of the clicked rectangle to a function witch will do different things depending on index.
        So in the repeater :

         onClicked: func(index)
        
        function func(ind){
        switch(ind){
        }
        }
        
        1 Reply Last reply
        1
        • D Offline
          D Offline
          DavidM29
          wrote on last edited by
          #4

          @GPBeta @LeLev
          Thanks for your anwser I believe both solutions could work. I'll try it.

          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