diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index 01cfc4034e..23245a7733 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -1469,6 +1469,8 @@ int QHeaderView::defaultSectionSize() const void QHeaderView::setDefaultSectionSize(int size) { Q_D(QHeaderView); + if (size < 0) + return; d->setDefaultSectionSize(size); } @@ -1502,6 +1504,8 @@ int QHeaderView::minimumSectionSize() const void QHeaderView::setMinimumSectionSize(int size) { Q_D(QHeaderView); + if (size < 0) + return; d->minimumSectionSize = size; } diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp index 75a7360699..45839d2ab3 100644 --- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp +++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp @@ -338,23 +338,21 @@ void tst_QHeaderView::getSetCheck() // int QHeaderView::defaultSectionSize() // void QHeaderView::setDefaultSectionSize(int) + obj1.setDefaultSectionSize(-1); + QVERIFY(obj1.defaultSectionSize() >= 0); obj1.setDefaultSectionSize(0); QCOMPARE(0, obj1.defaultSectionSize()); - obj1.setDefaultSectionSize(INT_MIN); - QCOMPARE(INT_MIN, obj1.defaultSectionSize()); obj1.setDefaultSectionSize(INT_MAX); QCOMPARE(INT_MAX, obj1.defaultSectionSize()); - // ### the test above does not make sense for values below 0 // int QHeaderView::minimumSectionSize() // void QHeaderView::setMinimumSectionSize(int) + obj1.setMinimumSectionSize(-1); + QVERIFY(obj1.minimumSectionSize() >= 0); obj1.setMinimumSectionSize(0); QCOMPARE(0, obj1.minimumSectionSize()); - obj1.setMinimumSectionSize(INT_MIN); - QCOMPARE(INT_MIN, obj1.minimumSectionSize()); obj1.setMinimumSectionSize(INT_MAX); QCOMPARE(INT_MAX, obj1.minimumSectionSize()); - // ### the test above does not make sense for values below 0 // int QHeaderView::offset() // void QHeaderView::setOffset(int)