QHeaderView: relayout on resetDefaultSectionSize
We now call setDefaultSectionSize with the new default section size. This clamps the value to min/max section size and it will resize affected sections. Pick-to: 6.5 Fixes: QTBUG-116013 Change-Id: I39849aca8d0672629ce0b3ca244038c27e045d4b Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit a8df174369cecd90f14dac85bf162353b7cb25d1) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
55a5cc4c93
commit
4253b2b6e7
@ -1560,13 +1560,14 @@ void QHeaderView::setDefaultSectionSize(int size)
|
||||
if (size < 0 || size > maxSizeSection)
|
||||
return;
|
||||
d->setDefaultSectionSize(size);
|
||||
d->customDefaultSectionSize = true;
|
||||
}
|
||||
|
||||
void QHeaderView::resetDefaultSectionSize()
|
||||
{
|
||||
Q_D(QHeaderView);
|
||||
if (d->customDefaultSectionSize) {
|
||||
d->updateDefaultSectionSizeFromStyle();
|
||||
d->setDefaultSectionSize(d->getDefaultSectionSizeFromStyle());
|
||||
d->customDefaultSectionSize = false;
|
||||
}
|
||||
}
|
||||
@ -2414,7 +2415,7 @@ bool QHeaderView::event(QEvent *e)
|
||||
break; }
|
||||
case QEvent::StyleChange:
|
||||
if (!d->customDefaultSectionSize)
|
||||
d->updateDefaultSectionSizeFromStyle();
|
||||
d->setDefaultSectionSize(d->getDefaultSectionSizeFromStyle());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -3881,7 +3882,6 @@ void QHeaderViewPrivate::setDefaultSectionSize(int size)
|
||||
executePostedLayout();
|
||||
invalidateCachedSizeHint();
|
||||
defaultSectionSize = size;
|
||||
customDefaultSectionSize = true;
|
||||
if (state == QHeaderViewPrivate::ResizeSection)
|
||||
preventCursorChangeInSetOffset = true;
|
||||
for (int i = 0; i < sectionItems.size(); ++i) {
|
||||
@ -3902,15 +3902,14 @@ void QHeaderViewPrivate::setDefaultSectionSize(int size)
|
||||
viewport->update();
|
||||
}
|
||||
|
||||
void QHeaderViewPrivate::updateDefaultSectionSizeFromStyle()
|
||||
int QHeaderViewPrivate::getDefaultSectionSizeFromStyle() const
|
||||
{
|
||||
Q_Q(QHeaderView);
|
||||
if (orientation == Qt::Horizontal) {
|
||||
defaultSectionSize = q->style()->pixelMetric(QStyle::PM_HeaderDefaultSectionSizeHorizontal, nullptr, q);
|
||||
} else {
|
||||
defaultSectionSize = qMax(q->minimumSectionSize(),
|
||||
q->style()->pixelMetric(QStyle::PM_HeaderDefaultSectionSizeVertical, nullptr, q));
|
||||
}
|
||||
Q_Q(const QHeaderView);
|
||||
return orientation == Qt::Horizontal
|
||||
? q->style()->pixelMetric(QStyle::PM_HeaderDefaultSectionSizeHorizontal, nullptr, q)
|
||||
: qMax(q->minimumSectionSize(),
|
||||
q->style()->pixelMetric(QStyle::PM_HeaderDefaultSectionSizeVertical, nullptr,
|
||||
q));
|
||||
}
|
||||
|
||||
void QHeaderViewPrivate::recalcSectionStartPos() const // linear (but fast)
|
||||
@ -4219,7 +4218,7 @@ bool QHeaderViewPrivate::read(QDataStream &in)
|
||||
if (in.status() == QDataStream::Ok) { // we haven't read past end
|
||||
customDefaultSectionSize = tmpbool;
|
||||
if (!customDefaultSectionSize)
|
||||
updateDefaultSectionSizeFromStyle();
|
||||
defaultSectionSize = getDefaultSectionSizeFromStyle();
|
||||
}
|
||||
|
||||
lastSectionSize = -1;
|
||||
|
@ -141,7 +141,7 @@ public:
|
||||
|
||||
inline void setDefaultValues(Qt::Orientation o) {
|
||||
orientation = o;
|
||||
updateDefaultSectionSizeFromStyle();
|
||||
defaultSectionSize = getDefaultSectionSizeFromStyle();
|
||||
defaultAlignment = (o == Qt::Horizontal
|
||||
? Qt::Alignment(Qt::AlignCenter)
|
||||
: Qt::AlignLeft|Qt::AlignVCenter);
|
||||
@ -309,7 +309,7 @@ public:
|
||||
void removeSectionsFromSectionItems(int start, int end);
|
||||
void resizeSectionItem(int visualIndex, int oldSize, int newSize);
|
||||
void setDefaultSectionSize(int size);
|
||||
void updateDefaultSectionSizeFromStyle();
|
||||
int getDefaultSectionSizeFromStyle() const;
|
||||
void recalcSectionStartPos() const; // not really const
|
||||
|
||||
inline int headerLength() const { // for debugging
|
||||
|
@ -423,6 +423,7 @@ private slots:
|
||||
void selectColumnsAndCells();
|
||||
void selectWithHeader_data();
|
||||
void selectWithHeader();
|
||||
void resetDefaultSectionSize();
|
||||
|
||||
#if QT_CONFIG(wheelevent)
|
||||
void mouseWheel_data();
|
||||
@ -4909,6 +4910,21 @@ void tst_QTableView::selectWithHeader()
|
||||
QVERIFY(!isSelected());
|
||||
}
|
||||
|
||||
void tst_QTableView::resetDefaultSectionSize()
|
||||
{
|
||||
// Create a table and change its default section size and then reset it.
|
||||
// This should be a no op so clicking on row 1 should select row 1 and not row
|
||||
// 0 as previously. QTBUG-116013
|
||||
QTableWidget view(10, 10);
|
||||
view.resize(300, 300);
|
||||
view.verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
|
||||
view.verticalHeader()->setDefaultSectionSize(120);
|
||||
view.verticalHeader()->resetDefaultSectionSize();
|
||||
view.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&view));
|
||||
QCOMPARE(view.verticalHeader()->logicalIndexAt(9, 45), 1);
|
||||
}
|
||||
|
||||
// This has nothing to do with QTableView, but it's convenient to reuse the QtTestTableModel
|
||||
#if QT_CONFIG(textmarkdownwriter)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user