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. Increment variable in Rectangle
Forum Updated to NodeBB v4.3 + New Features

Increment variable in Rectangle

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
7 Posts 2 Posters 1.1k 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.
  • T Offline
    T Offline
    Titi01
    wrote on last edited by
    #1

    Hello,

    I have a variable "b" and I want to increment it from 1 in the 1st rectangle and from 2 in the 2nd ....
    How can I do?
    Thanks

    property int b:1
    
    Rectangle{
    id:container1
    color:"red"
        Text  {      
            id : label
            anchors.centerIn: parent
            text : b // I would like it to display "2"
    }
    
    Rectangle{
    id:container2
    color:"blue"
        Text  {      
            id : label2
            anchors.centerIn: parent
            text : b // I would like it to display "3"
    }
    
    
    E 1 Reply Last reply
    0
    • T Titi01

      Hello,

      I have a variable "b" and I want to increment it from 1 in the 1st rectangle and from 2 in the 2nd ....
      How can I do?
      Thanks

      property int b:1
      
      Rectangle{
      id:container1
      color:"red"
          Text  {      
              id : label
              anchors.centerIn: parent
              text : b // I would like it to display "2"
      }
      
      Rectangle{
      id:container2
      color:"blue"
          Text  {      
              id : label2
              anchors.centerIn: parent
              text : b // I would like it to display "3"
      }
      
      
      E Offline
      E Offline
      Eeli K
      wrote on last edited by
      #2

      @Titi01 If the rectangles have the same properties, i.e. could be written once as a delegate, you can use Repeater. You can of course use the index property to change other properties conditionally, too.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Titi01
        wrote on last edited by
        #3

        Ok @Eeli-K but how do I increment in 2 different rectangles

        1 Reply Last reply
        0
        • T Offline
          T Offline
          Titi01
          wrote on last edited by
          #4

          @Wieland can you help me ?

          E 2 Replies Last reply
          0
          • T Titi01

            @Wieland can you help me ?

            E Offline
            E Offline
            Eeli K
            wrote on last edited by
            #5

            @Titi01 Did you already read the documentation of Repeater? The delegate has access to its index.

            1 Reply Last reply
            0
            • T Titi01

              @Wieland can you help me ?

              E Offline
              E Offline
              Eeli K
              wrote on last edited by
              #6

              @Titi01 But if you don't want to use Repeater and have just for example two or three rectangles, you can write

              id: label1
              text: b + 1
              ...
              id: label2
              text:  b + 2
              

              (instead of b+n use (b+n).toString() or "" + (b+n) or whatever works, I don't use javascript often enough to remember now.)

              Then the texts should change when the value of b changes, if that's what you want.

              1 Reply Last reply
              0
              • T Offline
                T Offline
                Titi01
                wrote on last edited by
                #7

                ok thanks you

                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