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. list-elemetns are not "paint"
QtWS25 Last Chance

list-elemetns are not "paint"

Scheduled Pinned Locked Moved Solved QML and Qt Quick
listqt4.8
7 Posts 3 Posters 1.7k 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.
  • P Offline
    P Offline
    petzold
    wrote on 11 Apr 2017, 13:30 last edited by
    #1

    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?

    1 Reply Last reply
    0
    • Y Offline
      Y Offline
      Yashpal
      wrote on 11 Apr 2017, 14:08 last edited by
      #2

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

      1 Reply Last reply
      0
      • P Offline
        P Offline
        petzold
        wrote on 12 Apr 2017, 06:12 last edited by
        #3

        Hi Yashpal,
        thanks for the fast reply.

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

        Y 1 Reply Last reply 12 Apr 2017, 07:38
        0
        • P petzold
          12 Apr 2017, 06:12

          Hi Yashpal,
          thanks for the fast reply.

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

          Y Offline
          Y Offline
          Yashpal
          wrote on 12 Apr 2017, 07:38 last edited by
          #4

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

          P 1 Reply Last reply 18 Apr 2017, 11:08
          0
          • Y Yashpal
            12 Apr 2017, 07:38

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

            P Offline
            P Offline
            petzold
            wrote on 18 Apr 2017, 11:08 last edited by
            #5

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

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Ray Gray
              wrote on 18 Apr 2017, 22:22 last edited by Ray Gray
              #6

              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)
                  }
              }
              
              1 Reply Last reply
              0
              • P Offline
                P Offline
                petzold
                wrote on 19 Apr 2017, 06:37 last edited by
                #7

                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

                1 Reply Last reply
                0

                6/7

                18 Apr 2017, 22:22

                • Login

                • Login or register to search.
                6 out of 7
                • First post
                  6/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved