Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.8.0, 5.12.1
Description
In the example we have nested ColumnLayout - ColumnLayout - RowLayout and the content of the RowLayout is aligned incorrectly and Text is not wrapped. Changing ColumnLayouts to GridLayouts doesn't help. Hence, I assume this problem concerns all QtQuick.Layouts.
The problem can be worked around by adding an Item with preferred width into the second ColumnLayout (the same where RowLayout resides). Also removing one layer of nesting seems to fix the problem.
See the attached images for reference: blue items denote correct layout (i.e. the workaround is used) and red items are wrong. Also the attached example shows the problem.
Tested on macOS and Windows 7.
QML from the attached example:
main.qml
import QtQuick 2.6 import QtQuick.Layouts 1.3 import QtQuick.Window 2.0 Window { id: root color: "white" visible: true width: 580 height: 480 ColumnLayout { anchors { margins: 10 fill: parent } readonly property var errors: [ "This is a long message that should wrap when the screen is narrow, and center when the screen is wide.", "This should be centered." ] // Note that blue messages behave properly, and red ones fail. // Also, IconMessage is a ColumnLayout, so it's automatically "Layout.fillWidth: true" IconMessage { iconColor: 'blue' messages: parent.errors[1] } IconMessage { iconColor: 'blue' messages: parent.errors[0] } IconMessage { enableSpanner: false iconColor: 'red' messages: parent.errors[1] } IconMessage { enableSpanner: false iconColor: 'red' messages: parent.errors[0] } Item { id: spacer Layout.fillHeight: true width: 1 } } }
IconMessage.qml
import QtQuick 2.6 import QtQuick.Layouts 1.3 // This Item should display a square icon with a wrapping message. // When the message is short, the row should center horizontally in the column. // When the message is wider than the column width, the message should wrap. ColumnLayout { id: root spacing: 0 property alias messages: icon_message.text property alias iconColor: icon_rect.color property alias enableSpanner: spanner.visible // When this "spanner" is not visible (or omitted), the layout breaks and nothing wraps or aligns Item { id: spanner Layout.fillWidth: true height: 1 } RowLayout { Layout.fillWidth: false Layout.maximumWidth: root.width Layout.alignment: Qt.AlignHCenter Rectangle { id: icon_rect width: 60 height: 60 color: 'black' } Text { id: icon_message Layout.fillWidth: true Layout.fillHeight: true Layout.maximumHeight: implicitHeight verticalAlignment: Text.AlignVCenter wrapMode: Text.Wrap maximumLineCount: 2 elide: Text.ElideRight font.pixelSize: 18 } } }