summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2017-10-31 16:05:58 +0100
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-01-06 05:17:00 +0000
commit20604ea554b282efa80502c68a499824f8692e7a (patch)
treeed1c27e6e482913d65c687c2a77ba68aa72c4df6 /src
parent1c0ac8c4b8646e898aa1636f93dcfd34949611cf (diff)
QHeaderView: respect min/maximumSectionSize property
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 <tmartsum@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/itemviews/qheaderview.cpp43
1 files changed, 40 insertions, 3 deletions
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;
}