path: root/src
diff options
authorJani Honkonen <>2012-06-07 16:39:21 +0200
committerQt by Nokia <>2012-06-14 10:11:26 +0200
commita85d15259ce2ce9371ad832bdd7becf256362c20 (patch)
tree2af24aba06b82c7f5fdfb534a94d427b728408d9 /src
parent6649171ddc2b7cfa93f9f38169cb307f3289dc85 (diff)
Fix QListView::scrollTo() when there are hidden rows
This is a cherry-pick of b0601630dd0ddabfaa3b97d042ee02b981d95988 from February QListView does not consider hidden rows when scrolling to an item. If there are hidden rows (or columns) before the selected item then the visual index of an item is not the same as the row index from the model. So scrolling will be off by the number of hidden rows before the selected item. Added a autotest for this also. Task-number: QTBUG-21115 Change-Id: I01b097bce7f163cdb480a71b763c060cc006fdc7 Reviewed-by: Stephen Kelly <>
Diffstat (limited to 'src')
1 files changed, 6 insertions, 1 deletions
diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp
index 315960648b..82792d5fef 100644
--- a/src/widgets/itemviews/qlistview.cpp
+++ b/src/widgets/itemviews/qlistview.cpp
@@ -3185,7 +3185,12 @@ int QListView::visualIndex(const QModelIndex &index) const
Q_D(const QListView);
QListViewItem itm = d->indexToListViewItem(index);
- return d->commonListView->itemIndex(itm);
+ int visualIndex = d->commonListView->itemIndex(itm);
+ for (int row = 0; row <= index.row() && visualIndex >= 0; row++) {
+ if (d->isHidden(row))
+ visualIndex--;
+ }
+ return visualIndex;