{
if (verticalScrollMode() == QAbstractItemView::ScrollPerItem) {
int value;
- if (scrollValueMap.isEmpty())
+ if (scrollValueMap.isEmpty()) {
value = 0;
- else
- value = qBound(0, scrollValueMap.at(verticalScrollBar()->value()), flowPositions.count() - 1);
+ } else {
+ int scrollBarValue = verticalScrollBar()->value();
+ int numHidden = 0;
+ for (int i = 0; i < flowPositions.count() - 1 && i <= scrollBarValue; ++i)
+ if (isHidden(i))
+ ++numHidden;
+ value = qBound(0, scrollValueMap.at(verticalScrollBar()->value()) - numHidden, flowPositions.count() - 1);
+ }
if (above)
hint = QListView::PositionAtTop;
else if (below)
void taskQTBUG_21804_hiddenItemsAndScrollingWithKeys();
void spacing_data();
void spacing();
+ void testScrollToWithHidden();
};
// Testing get/set functions
}
}
+void tst_QListView::testScrollToWithHidden()
+{
+ QListView lv;
+
+ QStringListModel model;
+ QStringList list;
+ for (int i = 0; i < 30; i++)
+ list << QString::number(i);
+ model.setStringList(list);
+ lv.setModel(&model);
+
+ lv.setRowHidden(1, true);
+ lv.setSpacing(5);
+
+ lv.show();
+ QTest::qWaitForWindowExposed(&lv);
+
+ QCOMPARE(lv.verticalScrollBar()->value(), 0);
+
+ lv.scrollTo(model.index(26, 0));
+ int expectedScrollBarValue = lv.verticalScrollBar()->value();
+ QVERIFY(expectedScrollBarValue != 0);
+
+ lv.scrollTo(model.index(25, 0));
+ QCOMPARE(expectedScrollBarValue, lv.verticalScrollBar()->value());
+}
QTEST_MAIN(tst_QListView)
#include "tst_qlistview.moc"