QML Layout does not limit the width of children

I have a QML ColumnLayout with multiple children and I want to constrain its width, for example:

ColumnLayout {

    width: 360
    height: 480

    ColumnLayout {
        id: inner
        Layout.maximumWidth: 200
        Layout.fillHeight: true

        Text {
            text: "Welcome"
            font.pixelSize: 18
        }

        Text {
            text: "Long explanation that should wrap, but ends up overflowing layout"
            wrapMode: Text.WrapAnywhere
        }
    }

    Rectangle {
        anchors.fill: inner
        z: -1
        border.color: "orange"
    }

}

      

I get the result shown in the image below.

enter image description here

The orange window shows the dimensions of the inner element of the layout and everything is in order. However, the layout text is not wrapped.

I can fix this by adding

Layout.maximumWidth: parent.width

      

for my "text" elements, but this is a rather awkward approach. Am I doing something wrong, or is this a Qt bug, or is this some design approach for some reason? I am using Qt 5.4.1.

+3


source to share


1 answer


Text will only be wrapped if explicit width is set

Documents



Text
{
    width: parent.width
}

      

+2


source







All Articles