diff options
author | Jan Arve Sæther <jan-arve.saether@qt.io> | 2024-04-30 11:00:28 +0200 |
---|---|---|
committer | Jan Arve Sæther <jan-arve.saether@qt.io> | 2024-04-30 17:27:55 +0000 |
commit | 6f7deef6d54dea7e033f5bf2c3ba0ee54ab562ed (patch) | |
tree | 002c500a5c08126758a2f15ac53eaf1b3efc97a0 /tests | |
parent | 5da51e012094c6aad75238a04e0897d43a4975c6 (diff) |
Do not try to rearrange if the width/height is < 0
This also fixes a crash in this peculiar condition:
Item {
width: 0
height: 0
RowLayout {
anchors.fill: parent
anchors.leftMargin: 1
anchors.leftMargin: 1
}
}
Reason for crash:
As a consequence the layout was rearranged with size == (-1, -1), (which
happens to be the value of uninitialized QSizeF).
This invalid size was passed down to QGridLayoutEngine::setGeometries()
(in the contentsGeometry QRect), and again to ensureGeometries().
ensureGeometries() would return early because of the condition
if (q_cachedSize == size)
(q_cachedSize is an uninitialized QSizeF by default, and size == (-1, -1)
This caused the q_xx, q_yy, q_widths, and q_height to not be properly
initialized, and it would crash inside
QGridLayoutEngine::setGeometries() when accessing the list:
qreal x = q_xx.at(item->firstColumn());
Pick-to: 6.2 6.5 6.7
Fixes: QTBUG-124456
Change-Id: I2e3586389aa1728c3622e92bd589af87d11955ae
Reviewed-by: Santhosh Kumar <santhosh.kumar.selvaraj@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qquicklayouts/data/tst_rowlayout.qml | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicklayouts/data/tst_rowlayout.qml b/tests/auto/quick/qquicklayouts/data/tst_rowlayout.qml index 03c186fdb4..d31a0b0fb8 100644 --- a/tests/auto/quick/qquicklayouts/data/tst_rowlayout.qml +++ b/tests/auto/quick/qquicklayouts/data/tst_rowlayout.qml @@ -1579,6 +1579,49 @@ Item { compare(rootRect.item1.width, 100) } + //--------------------------- + // Layout with negative size + Component { + id: negativeSize_Component + Item { + id: rootItem + width: 0 + height: 0 + // default width x height: (0 x 0) + RowLayout { + spacing: 0 + anchors.fill: parent + anchors.leftMargin: 1 // since parent size == (0 x 0), it causes layout size + anchors.bottomMargin: 1 // to become (-1, -1) + Item { + Layout.fillWidth: true + Layout.fillHeight: true + } + } + } + } + + function test_negativeSize() { + let rootItem = createTemporaryObject(negativeSize_Component, container) + let rowLayout = rootItem.children[0] + let item = rowLayout.children[0] + + const arr = [7, 1, 7, 0] + arr.forEach((n) => { + rootItem.width = n + rootItem.height = n + + // n === 0 is special: It will cause the layout to have a + // negative size. In this case it will simply not rearrange its + // child (and leave it at its previous size, 6) + const expectedItemExtent = n === 0 ? 6 : n - 1 + + compare(item.width, expectedItemExtent) + compare(item.height, expectedItemExtent) + }); + } + + //--------------------------- Component { id: rowlayoutWithTextItems_Component |