summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-07-13 11:38:04 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2021-07-16 17:01:25 +0200
commit26bebd2037eb69f7c939c899e3238a3e0f0a2376 (patch)
treea0ee48e5ea8e042a321992afe8ee90399378706e /src/widgets
parente4670df1182b1ec096ede3aad27828cfd85ecf1f (diff)
QListView: don't scroll if selected items are removed
For SingleSelection, removing the selected item will select the nearest item and, if autoScroll is enabled, ensures that the newly selected item is visible in the viewport. This may result in scrolling. For Multi- or ExtendedSelection, this should not happen, as having no selection is perfectly fine in those modes. However, QListView still tried to scroll to the current item in response to the currentIndexChanged signal. Since the currentIndex is at this point already hidden, the rectangle for it became invalid, and the attempt to scroll resulted in a one-pixel up-movement of the viewport (since the invalid rectangle has width == height == -1). Fix this by not scrolling if the rect for the index is invalid. Note that the index is still valid at this point, so we can't shortcut the call stack earlier. Add test that exercises the different combinations of ViewMode and SelectionMode, and demonstrates the one-pixel movement without the fix. Fixes: QTBUG-94788 Pick-to: 6.2 6.1 5.15 Change-Id: I1f36973eadb46e8c9b8b8068bc76ee09e9f490dd Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/itemviews/qlistview.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp
index 10e9fbb878..9b3221f84e 100644
--- a/src/widgets/itemviews/qlistview.cpp
+++ b/src/widgets/itemviews/qlistview.cpp
@@ -572,6 +572,8 @@ void QListView::scrollTo(const QModelIndex &index, ScrollHint hint)
return;
const QRect rect = visualRect(index);
+ if (!rect.isValid())
+ return;
if (hint == EnsureVisible && d->viewport->rect().contains(rect)) {
d->viewport->update(rect);
return;