QHeaderView - Fix auto-scroll on manual move on sections

This patch fixes the manual move of sections when auto scroll is on.
It is done in QAbstractItemView::doAutoScroll by letting the
qheaderView use its parents scrollbars if they are childs of a
QTableView or QTreeView.

Task-number: QTBUG-993
Task-number: QTBUG-1103

Change-Id: I70d999d9a07c3566e42d01cc5ebb47a69a83d9d4
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
Thorbjørn Lund Martsum 2012-10-31 16:01:53 +01:00 committed by The Qt Project
parent c6754c2720
commit 2e78d7ac30
3 changed files with 26 additions and 5 deletions

View File

@ -55,6 +55,9 @@
#include <qdatetime.h>
#include <qlineedit.h>
#include <qspinbox.h>
#include <qtreeview.h>
#include <qtableview.h>
#include <qheaderview.h>
#include <qstyleditemdelegate.h>
#include <private/qabstractitemview_p.h>
#include <private/qabstractitemmodel_p.h>
@ -3749,6 +3752,22 @@ void QAbstractItemView::doAutoScroll()
QScrollBar *verticalScroll = verticalScrollBar();
QScrollBar *horizontalScroll = horizontalScrollBar();
// QHeaderView does not (normally) have scrollbars
// It needs to use its parents scroll instead
QHeaderView *hv = qobject_cast<QHeaderView*>(this);
if (hv) {
QAbstractScrollArea *parent = qobject_cast<QAbstractScrollArea*>(parentWidget());
if (parent) {
if (hv->orientation() == Qt::Horizontal) {
if (!hv->horizontalScrollBar() || !hv->horizontalScrollBar()->isVisible())
horizontalScroll = parent->horizontalScrollBar();
} else {
if (!hv->verticalScrollBar() || !hv->verticalScrollBar()->isVisible())
verticalScroll = parent->verticalScrollBar();
}
}
}
int verticalStep = verticalScroll->pageStep();
int horizontalStep = horizontalScroll->pageStep();
if (d->autoScrollCount < qMax(verticalStep, horizontalStep))

View File

@ -2333,6 +2333,8 @@ void QHeaderView::mouseMoveEvent(QMouseEvent *e)
return;
}
case QHeaderViewPrivate::MoveSection: {
if (d->shouldAutoScroll(e->pos()))
d->startAutoScroll();
if (qAbs(pos - d->firstPos) >= QApplication::startDragDistance()
|| !d->sectionIndicator->isHidden()) {
int visual = visualIndexAt(pos);

View File

@ -97,14 +97,14 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
QTableView tv;
QStandardItemModel m;
m.setRowCount(10);
m.setColumnCount(36);
m.setRowCount(500);
m.setColumnCount(250);
tv.setModel(&m);
SomeHandler handler(tv.horizontalHeader(), &tv);
tv.horizontalHeader()->setDefaultSectionSize(50);
tv.horizontalHeader()->setDefaultSectionSize(30);
tv.show();
tv.horizontalHeader()->setSectionsMovable(true);
tv.showMaximized();
tv.verticalHeader()->setSectionsMovable(true);
app.exec();
}
#include "qheaderviewtest1.moc"