QFormLayout: Avoid assertion with negative spacings.

It's not really clear if styles *must* return a non-negative value for
QStyle::pixelMetric(PM_Layout{Vertical,Horizontal}Spacing), but both
QBoxLayout and QGridLayout seems to be robust enough to handle this.
They will simply make sure that the spacing is never negative.
We therefore make QFormLayout equally robust.

Task-number: QTBUG-34731

Change-Id: I62235bfcd8adf7757cf15bc9927b29650ae6459d
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
This commit is contained in:
Jan Arve Saether 2013-11-13 10:35:17 +01:00 committed by The Qt Project
parent 191f96cb88
commit de5b3780cf
2 changed files with 15 additions and 1 deletions

View File

@ -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)

View File

@ -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;
}