From 20604ea554b282efa80502c68a499824f8692e7a Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Tue, 31 Oct 2017 16:05:58 +0100 Subject: QHeaderView: respect min/maximumSectionSize property MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QHeaderView::resizeSection() did not check if the given section size is inside the min/max property bounds. Also on calling setMin/MaximumSectionSize() the current section sizes were not checked if they are inside the new given bounds. This is a small behavior change when a user is setting the section size via resizeSection() without respecting the min/maxSectionSizes. Task-number: QTBUG-64173 Change-Id: Ia9c9eebf058d60c776ab5f8f8336642013ec553f Reviewed-by: Thorbjørn Lund Martsum --- src/widgets/itemviews/qheaderview.cpp | 43 ++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index 6ee3f0cfca..a21b8feeb1 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -886,6 +886,10 @@ void QHeaderView::resizeSection(int logical, int size) if (logical < 0 || logical >= count() || size < 0 || size > maxSizeSection) return; + // make sure to not exceed bounds when setting size programmatically + if (size > 0) + size = qBound(minimumSectionSize(), size, maximumSectionSize()); + if (isSectionHidden(logical)) { d->hiddenSectionSize.insert(logical, size); return; @@ -1661,9 +1665,25 @@ void QHeaderView::setMinimumSectionSize(int size) Q_D(QHeaderView); if (size < -1 || size > maxSizeSection) return; + // larger new min size - check current section sizes + const bool needSizeCheck = size > d->minimumSectionSize; d->minimumSectionSize = size; if (d->minimumSectionSize > maximumSectionSize()) - d->maximumSectionSize = size; + setMaximumSectionSize(size); + + if (needSizeCheck) { + if (d->hasAutoResizeSections()) { + d->doDelayedResizeSections(); + } else { + for (int visual = 0; visual < d->sectionCount(); ++visual) { + if (d->isVisualIndexHidden(visual)) + continue; + if (d->headerSectionSize(visual) < d->minimumSectionSize) + resizeSection(logicalIndex(visual), size); + } + } + } + } /*! @@ -1700,7 +1720,22 @@ void QHeaderView::setMaximumSectionSize(int size) if (minimumSectionSize() > size) d->minimumSectionSize = size; + // smaller new max size - check current section sizes + const bool needSizeCheck = size < d->maximumSectionSize; d->maximumSectionSize = size; + + if (needSizeCheck) { + if (d->hasAutoResizeSections()) { + d->doDelayedResizeSections(); + } else { + for (int visual = 0; visual < d->sectionCount(); ++visual) { + if (d->isVisualIndexHidden(visual)) + continue; + if (d->headerSectionSize(visual) > d->maximumSectionSize) + resizeSection(logicalIndex(visual), size); + } + } + } } @@ -3431,9 +3466,11 @@ void QHeaderViewPrivate::resizeSections(QHeaderView::ResizeMode globalMode, bool int logicalIndex = q->logicalIndex(i); sectionSize = qMax(viewSectionSizeHint(logicalIndex), q->sectionSizeHint(logicalIndex)); - if (sectionSize > q->maximumSectionSize()) - sectionSize = q->maximumSectionSize(); } + sectionSize = qBound(q->minimumSectionSize(), + sectionSize, + q->maximumSectionSize()); + section_sizes.append(sectionSize); lengthToStretch -= sectionSize; } -- cgit v1.2.3