QAIV - Fix scollbars with ScrollPerPixel to scroll 1 pixel.

The documentation says that we scroll one pixel

Quote:
"QAbstractItemView::ScrollPerPixel  (value 1)"
"The view will scroll the contents one pixel at a time."

However until now Qt has tried to be smarter than the
documentation, but is actually getting in the way of the user,
where a manual set value to setSingleStep will continuingly
be overwritten (on e.g resize).

This patch ensures the behavior described in the documentation
for the vertical headers - and leaves the control to the user.

[ChangeLog][QtWidgets][QAbstractItemView]  QTBUG-7232 - In ItemViews
scrollbars will now by default only scroll 1 pixel when scrollMode
is set to scrollPerPixel. That is it will (when scrollMode is
scrollPerPixel) do what is stated in the documentation, and no
longer automatically adjust the scrollbars singleStep. The user
can now control that value.

Task-number: QTBUG-7232

Change-Id: I8a61d3100be65d0c4ee32aad58caed019aa2669c
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
Thorbjørn Lund Martsum 2012-11-07 19:06:01 +01:00 committed by The Qt Project
parent 94dca6d10c
commit 934f062203
4 changed files with 8 additions and 8 deletions

View File

@ -1835,16 +1835,16 @@ void QCommonListViewBase::removeHiddenRow(int row)
void QCommonListViewBase::updateHorizontalScrollBar(const QSize &step)
{
horizontalScrollBar()->setSingleStep(step.width() + spacing());
horizontalScrollBar()->setPageStep(viewport()->width());
horizontalScrollBar()->setRange(0, contentsSize.width() - viewport()->width());
// we do not want to overwrite (a possible user set) single step
}
void QCommonListViewBase::updateVerticalScrollBar(const QSize &step)
void QCommonListViewBase::updateVerticalScrollBar(const QSize & /*step*/)
{
verticalScrollBar()->setSingleStep(step.height() + spacing());
verticalScrollBar()->setPageStep(viewport()->height());
verticalScrollBar()->setRange(0, contentsSize.height() - viewport()->height());
// we do not want to overwrite (a possible user set) single step
}
void QCommonListViewBase::scrollContentsBy(int dx, int dy, bool /*scrollElasticBand*/)

View File

@ -2176,7 +2176,7 @@ void QTableView::updateGeometries()
} else { // ScrollPerPixel
horizontalScrollBar()->setPageStep(vsize.width());
horizontalScrollBar()->setRange(0, horizontalLength - vsize.width());
horizontalScrollBar()->setSingleStep(qMax(vsize.width() / (columnsInViewport + 1), 2));
// here we do not want to overwrite (a possible user set) single step
}
// vertical scroll bar
@ -2204,7 +2204,7 @@ void QTableView::updateGeometries()
} else { // ScrollPerPixel
verticalScrollBar()->setPageStep(vsize.height());
verticalScrollBar()->setRange(0, verticalLength - vsize.height());
verticalScrollBar()->setSingleStep(qMax(vsize.height() / (rowsInViewport + 1), 2));
// here we do not want to overwrite (a possible user set) single step
}
d->geometryRecursionBlock = false;

View File

@ -3666,7 +3666,7 @@ void QTreeViewPrivate::updateScrollBars()
}
vbar->setRange(0, contentsHeight - viewportSize.height());
vbar->setPageStep(viewportSize.height());
vbar->setSingleStep(qMax(viewportSize.height() / (itemsInViewport + 1), 2));
// here we do not want to overwrite (a possible user set) single step
}
const int columnCount = header->count();
@ -3692,7 +3692,7 @@ void QTreeViewPrivate::updateScrollBars()
viewportSize = maxSize;
hbar->setPageStep(viewportSize.width());
hbar->setRange(0, qMax(horizontalLength - viewportSize.width(), 0));
hbar->setSingleStep(qMax(viewportSize.width() / (columnsInViewport + 1), 2));
// here we do not want to overwrite (a possible user set) single step
}
}

View File

@ -3702,7 +3702,7 @@ void tst_QTableView::mouseWheel_data()
<< 10 + qApp->wheelScrollLines() << 10 + qApp->wheelScrollLines();
QTest::newRow("scroll down per pixel")
<< int(QAbstractItemView::ScrollPerPixel) << -120
<< 10 + qApp->wheelScrollLines() * 89 << 10 + qApp->wheelScrollLines() * 28;
<< 10 + qApp->wheelScrollLines() << 10 + qApp->wheelScrollLines();
}
void tst_QTableView::mouseWheel()