From cf366e8b862a616efd7c3d4683d59971f795d476 Mon Sep 17 00:00:00 2001
From: Jan Arve Saether <jan-arve.saether@digia.com>
Date: Fri, 24 May 2013 17:55:21 +0200
Subject: [PATCH] Made sure items with preferred width of 0 could also stretch

If no stretch factors were specified, we used the preferred size as a
stretch factor. Obviously, that didn't work if the preferred size was
actually 0.

This patch works around this by actually setting the stretch factor to
1.0 if this is the case.
This should work fine in most cases, except for the case where there
are also other items with a preferred size close to 0.
In this case, the item with preferred size 0 will just grow
faster than an item with e.g. preferred size 0.1.

Task-number: QTBUG-31217

Change-Id: I966455da0bdd00308591c7f7cfbc4e134d423e57
Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
---
 src/widgets/graphicsview/qgridlayoutengine.cpp       |  2 +-
 .../qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp  | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/widgets/graphicsview/qgridlayoutengine.cpp b/src/widgets/graphicsview/qgridlayoutengine.cpp
index b80612bc474..4f43a0a4ac1 100644
--- a/src/widgets/graphicsview/qgridlayoutengine.cpp
+++ b/src/widgets/graphicsview/qgridlayoutengine.cpp
@@ -291,7 +291,7 @@ void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSiz
 
                     int stretch = stretches[start + i];
                     if (sumStretches == 0) {
-                        if (hasIgnoreFlag) {
+                        if (hasIgnoreFlag || sizes[i] == 0.0) {
                             factors[i] = (stretch < 0) ? 1.0 : 0.0;
                         } else {
                             factors[i] = (stretch < 0) ? sizes[i] : 0.0;
diff --git a/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp b/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp
index 41e5ed466c1..8c8f27d635f 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp
@@ -1884,6 +1884,18 @@ void tst_QGraphicsGridLayout::defaultStretchFactors_data()
                                 << QSizeF(10,10) << QSizeF(10,10) << QSizeF(10,10)
                             );
 
+    QTest::newRow("preferredsizeIsZero") << (ItemList()
+                                    << ItemDesc(0,0)
+                                        .preferredSizeHint(QSizeF(0,10))
+                                    << ItemDesc(0,1)
+                                        .preferredSizeHint(QSizeF(10,10))
+                                        .maxSize(QSizeF(20, 10))
+                                )
+                            << QSizeF(30, 10)
+                            << (SizeList()
+                                << QSizeF(10,10) << QSizeF(20,10)
+                            );
+
     QTest::newRow("ignoreitem01") << (ItemList()
                                     << ItemDesc(0,0)
                                         .preferredSizeHint(QSizeF(10,10))
-- 
GitLab