summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/widgets/itemviews/qheaderview.cpp2
-rw-r--r--tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp10
2 files changed, 11 insertions, 1 deletions
diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp
index b52c2d6038..83c4fd0071 100644
--- a/src/widgets/itemviews/qheaderview.cpp
+++ b/src/widgets/itemviews/qheaderview.cpp
@@ -874,7 +874,7 @@ void QHeaderView::swapSections(int first, int second)
void QHeaderView::resizeSection(int logical, int size)
{
Q_D(QHeaderView);
- if (logical < 0 || logical >= count())
+ if (logical < 0 || logical >= count() || size < 0)
return;
if (isSectionHidden(logical)) {
diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
index 62da3337e1..2a0a40f542 100644
--- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
+++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
@@ -172,6 +172,7 @@ private slots:
void removeSection();
void preserveHiddenSectionWidth();
void invisibleStretchLastSection();
+ void noSectionsWithNegativeSize();
void emptySectionSpan();
void task236450_hidden_data();
@@ -1853,6 +1854,15 @@ void tst_QHeaderView::invisibleStretchLastSection()
QCOMPARE(view.sectionSize(count - 1), view.defaultSectionSize() * 2);
}
+void tst_QHeaderView::noSectionsWithNegativeSize()
+{
+ QStandardItemModel m(4, 4);
+ QHeaderView h(Qt::Horizontal);
+ h.setModel(&m);
+ h.resizeSection(1, -5);
+ QVERIFY(h.sectionSize(1) >= 0); // Sections with negative sizes not well defined.
+}
+
void tst_QHeaderView::emptySectionSpan()
{
QHeaderViewPrivate::SectionSpan span;