[Qt-qml] Column has unexpected width

John Temples qt-qml at xargs.com
Fri Sep 23 20:14:32 CEST 2011


In the code below, there are two Columns, with the second Column
anchored to the right of the first one.  The first Column ends up with
a width of -1, and the second Column has an x of -1.  Can someone
explain why this happens?  I would have thought the Item would assume
the size of its child Rectangle and wouldn't need to have a size
explicitly provided.

import QtQuick 1.0

Rectangle {
     width: 800
     height: 480

     Column {
         id: column_1
         height: parent.height

         // adding a width to the Item fixes the problem, as does
         // removing the Item and just having a Rectangle.

         Item {
             height: 100
             //width: childrenRect.width

             Rectangle {
                 height: 50;
                 width: 50;
                 color: "red"
             }
         }

         // width = -1
         Component.onCompleted: console.debug("width =", width)
     }

     Column {
         anchors.left: column_1.right

         Rectangle {
             height: 50
             width:50
             color: "blue"
         }

         // x = -1
         Component.onCompleted: console.debug("x =", x)
     }
}

--
John W. Temples, III


More information about the Qt-qml mailing list