diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2021-07-13 11:38:04 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-07-17 10:24:43 +0000 |
commit | 4b42bca2092125071092f2de0a193ed945de58eb (patch) | |
tree | 8dba2e6aad8e9e0606bca22e22d67d428ee099c1 /src/widgets/itemviews | |
parent | e54d6459d246a167befcea1a39b162ecd49642a4 (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
Change-Id: I1f36973eadb46e8c9b8b8068bc76ee09e9f490dd
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
(cherry picked from commit 26bebd2037eb69f7c939c899e3238a3e0f0a2376)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/widgets/itemviews')
-rw-r--r-- | src/widgets/itemviews/qlistview.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp index 4c87f7dd6a..b0de33afaf 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; |