list-elemetns are not "paint"
-
wrote on 11 Apr 2017, 13:30 last edited by
Hi guys,
i need your help.
I want make a list of some QML-objects (Rectangle) because i want check some buttons actions the state of that rectangles. i work with QT4.8 with QtQuick1.0
for that i want make a list with all my rectangles
see the code belowproperty list<Rectangle> buttonList buttonList: [ Rectangle{ x: 0 y: 100 }, Rectangle{ x: 0 y: 200 } ]
If i check now my list it is nothing paint in my application. but if i check buttonList.length the list is created with the value of 2.
What i'm doing wrong?
-
wrote on 12 Apr 2017, 06:12 last edited by
Hi Yashpal,
thanks for the fast reply.i don't understand completly what you mean can you explain it a little bit more detailed?
-
Hi Yashpal,
thanks for the fast reply.i don't understand completly what you mean can you explain it a little bit more detailed?
wrote on 12 Apr 2017, 07:38 last edited by@petzold I mean to say you haven't attached the rectangles maintained in the list to a root item of the scene due to which you are unable to see rectangles when you run code. So, please attach those rectangles to root items to see them. Also, make sure to give width and height to those rectangles.
-
@petzold I mean to say you haven't attached the rectangles maintained in the list to a root item of the scene due to which you are unable to see rectangles when you run code. So, please attach those rectangles to root items to see them. Also, make sure to give width and height to those rectangles.
wrote on 18 Apr 2017, 11:08 last edited byHi Yashpal
I understood but i did what you say here see full code of that.
Rectangle{ property list<Rectangle> test1: [ Rectangle{ id: ma0 x: -451 y: 8 width: 100 height: 30 }, Rectangle{ id: m1 x: -451 y: 103 width: 100 height: 30 } ] }
And the same story like before. It is nothing rendered. Maybe i misunderstood something what you say.
If i use the "children"-list it works but not with a own created list. -
wrote on 18 Apr 2017, 22:22 last edited by Ray Gray
petzold, your code just defines a variable (==property) named buttonList/test1 that contains list of objects (==rectangles). This is just a variable and it's not a part of (visible) items' hierarchy. If you'd like to make a collection of such items, do something like this:
import QtQuick 2.0 Rectangle{ // collection of items property variant test1: [m0, m1] Rectangle{ id: m0 x: 0 y: 8 color: "red" width: 100 height: 30 } Rectangle{ id: m1 x: 0 y: 103 color: "yellow" width: 100 height: 30 } Component.onCompleted: { console.log("y of 1st rect: ", test1[0].y) console.log("y of 2nd rect: ", test1[1].y) } }
-
wrote on 19 Apr 2017, 06:37 last edited by
Hi Ray,
thanks for that tip. Now i understood the way how it works.
i already tried and it works.
thanks both of you
-> solved
5/7