QHeaderView: respect min/maxSectionSize in setDefaultSectionSize()

The min/max section size was not checked when setting the default
section size. This was an oversight when the check for min/max section
size was added to resizeSection().

[ChangeLog][QtWidgets][QHeaderView] setDefaultSectionSize() now
checks if the given value is inside min/max section size

Task-number: QTBUG-69431
Change-Id: I1b5704282927ce5a8520f52174ebf91d9840bc8a
Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
bb10
Christian Ehrlicher 2018-07-24 20:44:05 +02:00
parent f29c955483
commit faff43348b
2 changed files with 11 additions and 0 deletions

View File

@ -3834,6 +3834,7 @@ void QHeaderViewPrivate::cascadingResize(int visual, int newSize)
void QHeaderViewPrivate::setDefaultSectionSize(int size)
{
Q_Q(QHeaderView);
size = qBound(q->minimumSectionSize(), size, q->maximumSectionSize());
executePostedLayout();
invalidateCachedSizeHint();
defaultSectionSize = size;

View File

@ -405,6 +405,7 @@ void tst_QHeaderView::getSetCheck()
// int QHeaderView::defaultSectionSize()
// void QHeaderView::setDefaultSectionSize(int)
obj1.setMinimumSectionSize(0);
obj1.setDefaultSectionSize(-1);
QVERIFY(obj1.defaultSectionSize() >= 0);
obj1.setDefaultSectionSize(0);
@ -2060,6 +2061,7 @@ void tst_QHeaderView::defaultSectionSize()
QHeaderView h((Qt::Orientation)direction);
h.setModel(&m);
h.setMinimumSectionSize(0);
QCOMPARE(h.defaultSectionSize(), oldDefaultSize);
h.setDefaultSectionSize(newDefaultSize);
@ -3326,8 +3328,16 @@ void tst_QHeaderView::testMinMaxSectionSize()
QHeaderView &header = *tv.horizontalHeader();
header.setMinimumSectionSize(sectionSizeMin);
header.setMaximumSectionSize(sectionSizeMax);
// check bounds for default section size
header.setDefaultSectionSize(sectionSizeMin - 1);
QCOMPARE(header.defaultSectionSize(), sectionSizeMin);
header.setDefaultSectionSize(sectionSizeMax + 1);
QCOMPARE(header.defaultSectionSize(), sectionSizeMax);
header.setDefaultSectionSize(defaultSectionSize);
QCOMPARE(header.defaultSectionSize(), defaultSectionSize);
header.setStretchLastSection(stretchLastSection);
QCOMPARE(header.stretchLastSection(), stretchLastSection);
// check defaults
QCOMPARE(header.sectionSize(0), defaultSectionSize);