Why Item couldn't positioned in Row/Column in QML?



  • Hello,

    Why Item in QML couldn't positioned in Row/Column?

      Column
        {
            Item {
                id: name0
                Rectangle
                {
                    width: 50
                    height: 50
                    color:"blue"
                }
            }
    
            Item {
                id: name1
                Rectangle
                {
                    width: 50
                    height: 50
                    color:"red"
                }
            }
        }
    

    the red rectangle put on the blue?


  • Moderators

    @Alien
    because the wrapper Items (around the rectangles) do not have a width/height set, so they are overlapping



  • @Alien give a width/height to your Item elements

    Column
            {
               // anchors.fill: parent
                Item {
                    id: name0
                    width: 50
                    height: 50
                    Rectangle
                    {
                         anchors.fill:parent
                        color:"blue"
                    }
                }
    
                Item {
                    id: name1
                    width: 50
                    height: 50
                    Rectangle
                    {
                        anchors.fill:parent
                        color:"red"
                    }
                }
            }
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.