0

Below is part of my code. It's working fine, however I spent a lot of time trying to solve it with Repeater to be more elegant and flexible, but couldn't.

Could you please suggest a solution to me? The areaMachine is in an other qml file.

Row {
        id: pageIndicatorBoxes
        anchors.centerIn: pageIndicatorLine
        spacing: 5

        Rectangle {
            id: pageIndicatorBox1
            width: 10
            height: 10
            color: areaMachine.page == 1 ? "#e5e5e5" : "#404040"
        }

        Rectangle {
            id: pageIndicatorBox2
            width: 10
            height: 10
            color: areaMachine.page == 2 ? "#e5e5e5" : "#404040"
        }

        Rectangle {
            id: pageIndicatorBox3
            width: 10
            height: 10
            color: areaMachine.page == 3 ? "#e5e5e5" : "#404040"
        }

        Rectangle {
            id: pageIndicatorBox4
            width: 10
            height: 10
            color: areaMachine.page == 4 ? "#e5e5e5" : "#404040"
        }
    }
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

Looks like you haven't look into the documentation about Repeater and its main delegate property. There you can find code examples that fits your problem, so you can combine it and have something like:

  Row {
    id: pageIndicatorBoxes
    anchors.centerIn: pageIndicatorLine
    spacing: 5
    
    Repeater {
      model: 4
      Rectangle {
        id: pageIndicatorBox1
        width: 10
        height: 10
        color: (areaMachine.page === (index + 1)) ? "#e5e5e5" : "#404040"
      }
    }
  }
NG_
  • 6,895
  • 7
  • 45
  • 67
  • 1
    I did and I tried it with several functions/variations. Just not this 'simplestestest' approach. :S Thanks. – Tamás Grábler Jan 25 '21 at 10:15
  • Great to hear it helps. You can mark it as an answer then. For a further development I can advice you to have a separate as-simple-as-possible-application where you can try new components/concepts and then -> apply your results into real application you are working on. – NG_ Jan 25 '21 at 10:17
  • 1
    The only thing to correct is: I need (index + 1). – Tamás Grábler Jan 25 '21 at 10:19
  • Sure thing. Updated an answer. – NG_ Jan 25 '21 at 10:20