QHeaderView: use correct mouse position for auto scroll

QHeaderView::mouseMoveEvent started autoscroll without propagating the
event's mouse position to QAbstractItemViewPrivate::draggedPosition.
This data member always containing QPoint() has lead to right drags not
causing an autoscroll at all. Left drags with a scroll offset just
kept scrolling until the offset was 0.

The missing propagation has been added.
As a drive by, dead code has been removed and the local variable pos
has been constified.

Fixes: QTBUG-113573
Change-Id: I7b194dfc71abea6f2bbaaae18270c80eb15afb4d
Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
(cherry picked from commit 787b4c1506aba7e83d861e178329a18c6ec34322)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Axel Spoerl 2023-06-13 12:12:43 +02:00 committed by Qt Cherry-pick Bot
parent 596c9a71fa
commit a84d0b6bab

View File

@ -2579,7 +2579,7 @@ void QHeaderView::mousePressEvent(QMouseEvent *e)
void QHeaderView::mouseMoveEvent(QMouseEvent *e) void QHeaderView::mouseMoveEvent(QMouseEvent *e)
{ {
Q_D(QHeaderView); Q_D(QHeaderView);
int pos = d->orientation == Qt::Horizontal ? e->position().toPoint().x() : e->position().toPoint().y(); const int pos = d->orientation == Qt::Horizontal ? e->position().toPoint().x() : e->position().toPoint().y();
if (pos < 0 && d->state != QHeaderViewPrivate::SelectSections) if (pos < 0 && d->state != QHeaderViewPrivate::SelectSections)
return; return;
if (e->buttons() == Qt::NoButton) { if (e->buttons() == Qt::NoButton) {
@ -2607,8 +2607,10 @@ void QHeaderView::mouseMoveEvent(QMouseEvent *e)
return; return;
} }
case QHeaderViewPrivate::MoveSection: { case QHeaderViewPrivate::MoveSection: {
if (d->shouldAutoScroll(e->position().toPoint())) if (d->shouldAutoScroll(e->position().toPoint())) {
d->draggedPosition = e->pos();
d->startAutoScroll(); d->startAutoScroll();
}
if (qAbs(pos - d->firstPos) >= QApplication::startDragDistance() if (qAbs(pos - d->firstPos) >= QApplication::startDragDistance()
#if QT_CONFIG(label) #if QT_CONFIG(label)
|| !d->sectionIndicator->isHidden() || !d->sectionIndicator->isHidden()
@ -3805,12 +3807,9 @@ void QHeaderViewPrivate::cascadingResize(int visual, int newSize)
if (currentSectionSize <= minimumSize) if (currentSectionSize <= minimumSize)
continue; continue;
int newSectionSize = qMax(currentSectionSize - delta, minimumSize); int newSectionSize = qMax(currentSectionSize - delta, minimumSize);
//qDebug() << "### cascading to" << i << newSectionSize - currentSectionSize << delta;
resizeSectionItem(i, currentSectionSize, newSectionSize); resizeSectionItem(i, currentSectionSize, newSectionSize);
saveCascadingSectionSize(i, currentSectionSize); saveCascadingSectionSize(i, currentSectionSize);
delta = delta - (currentSectionSize - newSectionSize); delta = delta - (currentSectionSize - newSectionSize);
//qDebug() << "new delta" << delta;
//if (newSectionSize != minimumSize)
if (delta <= 0) if (delta <= 0)
break; break;
} }
@ -3828,7 +3827,6 @@ void QHeaderViewPrivate::cascadingResize(int visual, int newSize)
int newSectionSize = currentSectionSize - delta; int newSectionSize = currentSectionSize - delta;
resizeSectionItem(i, currentSectionSize, newSectionSize); resizeSectionItem(i, currentSectionSize, newSectionSize);
if (newSectionSize >= originalSectionSize && false) { if (newSectionSize >= originalSectionSize && false) {
//qDebug() << "section" << i << "restored to" << originalSectionSize;
cascadingSectionSize.remove(i); // the section is now restored cascadingSectionSize.remove(i); // the section is now restored
} }
sectionResized = true; sectionResized = true;