summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/widgets/kernel/qformlayout.cpp2
-rw-r--r--tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp14
2 files changed, 15 insertions, 1 deletions
diff --git a/src/widgets/kernel/qformlayout.cpp b/src/widgets/kernel/qformlayout.cpp
index e1376c754f..c1d3e95e7a 100644
--- a/src/widgets/kernel/qformlayout.cpp
+++ b/src/widgets/kernel/qformlayout.cpp
@@ -641,7 +641,7 @@ static inline int spacingHelper(QWidget* parent, QStyle *style, int userVSpacing
spacing = qMax(spacing, prevItem2->geometry().top() - wid->geometry().top() );
}
}
- return spacing;
+ return qMax(spacing, 0);
}
static inline void initLayoutStruct(QLayoutStruct& sl, QFormLayoutItem* item)
diff --git a/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp b/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp
index 135605f185..d04b812878 100644
--- a/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp
+++ b/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp
@@ -47,6 +47,7 @@
#include <qproxystyle.h>
#include <qsizepolicy.h>
+#include <QtWidgets/QCheckBox>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>
@@ -347,6 +348,19 @@ void tst_QFormLayout::spacing()
style->hspacing = 20;
//QCOMPARE(fl->spacing(), 20);
+
+
+ // Do not assert if spacings are negative (QTBUG-34731)
+ style->vspacing = -1;
+ style->hspacing = -1;
+ QLabel *label = new QLabel(tr("Asserts"));
+ QCheckBox *checkBox = new QCheckBox(tr("Yes"));
+ fl->setWidget(0, QFormLayout::LabelRole, label);
+ fl->setWidget(1, QFormLayout::FieldRole, checkBox);
+ w->resize(200, 100);
+ w->show();
+ QVERIFY(QTest::qWaitForWindowExposed(w));
+
delete w;
delete style;
}