list-elemetns are not "paint"



  • 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 below

    property 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?



  • @petzold The rectangles are rendered but, it doesn't have the parent set i.e, NULL. That is the reason rectangles are shown.



  • Hi Yashpal,
    thanks for the fast reply.

    i don't understand completly what you mean can you explain it a little bit more detailed?



  • @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.



  • @Yashpal

    Hi 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.



  • 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)
        }
    }
    


  • 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


Log in to reply