Unsolved Increment variable in Rectangle
-
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?
Thanksproperty 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" }
-
@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.
-
Ok @Eeli-K but how do I increment in 2 different rectangles
-
@Wieland can you help me ?
-
@Titi01 Did you already read the documentation of Repeater? The delegate has access to its index.
-
@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.
-
ok thanks you