diff options
author | Oliver Eftevaag <oliver.eftevaag@qt.io> | 2022-01-07 15:43:59 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-01-20 18:33:06 +0000 |
commit | def37f47b0b07070ef1395adeab092406fe13af2 (patch) | |
tree | 73471dab445a2799d75c8f18aa5c07ae988d5e6e /src | |
parent | 905eea6c506eb87079d416fdd8e2ec640a7c130d (diff) |
QQuickListView: Stop overlap for section and firstItem delegates
Problem:
The first delegate after a section delegate would have the same position
as the section delegate, if the section delegate is invisible during
initialization.
In case the section delegates become visible later on during program
execution, the delegates would be re-positioned again in the
QQuickListViewPrivate::layoutVisibleItems function.
But this would not call setPosition for the first item (delegate).
It would only call setPosition for all delegates after the first one.
This would mean that the position for the first delegate would never be
updated, after the delegate was first created.
Solution:
Call FxListItemSG::setPosition() for the first item in
QQuickListViewPrivate::layoutVisibleItems, just like we're already doing
for all the items after the first one in the for-loop.
Fixes: QTBUG-94848
Change-Id: I34a5ada336ab507b31e3675a1c11eba066fa139a
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
(cherry picked from commit 3aad05bc09f40d81df7748cbc246974230a3ca17)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/quick/items/qquickitemview.cpp | 2 | ||||
-rw-r--r-- | src/quick/items/qquicklistview.cpp | 7 |
2 files changed, 7 insertions, 2 deletions
diff --git a/src/quick/items/qquickitemview.cpp b/src/quick/items/qquickitemview.cpp index bd82fc14d3..c92033bb28 100644 --- a/src/quick/items/qquickitemview.cpp +++ b/src/quick/items/qquickitemview.cpp @@ -1989,7 +1989,7 @@ bool QQuickItemViewPrivate::applyModelChanges(ChangeResult *totalInsertionResult updateUnrequestedIndexes(); - FxViewItem *prevVisibleItemsFirst = visibleItems.count() ? *visibleItems.constBegin() : 0; + FxViewItem *prevVisibleItemsFirst = visibleItems.count() ? *visibleItems.constBegin() : nullptr; int prevItemCount = itemCount; int prevVisibleItemsCount = visibleItems.count(); bool visibleAffected = false; diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp index 7d1829858d..c35fc5224c 100644 --- a/src/quick/items/qquicklistview.cpp +++ b/src/quick/items/qquicklistview.cpp @@ -896,13 +896,18 @@ void QQuickListViewPrivate::layoutVisibleItems(int fromModelIndex) const qreal from = isContentFlowReversed() ? -position()-displayMarginBeginning-size() : position()-displayMarginBeginning; const qreal to = isContentFlowReversed() ? -position()+displayMarginEnd : position()+size()+displayMarginEnd; - FxViewItem *firstItem = *visibleItems.constBegin(); + FxListItemSG *firstItem = static_cast<FxListItemSG *>(visibleItems.constFirst()); bool fixedCurrent = currentItem && firstItem->item == currentItem->item; firstVisibleItemPosition = firstItem->position(); qreal sum = firstItem->size(); qreal pos = firstItem->position() + firstItem->size() + spacing; firstItem->setVisible(firstItem->endPosition() >= from && firstItem->position() <= to); + // setPosition will affect the position of the item, and its section, if it has one. + // This will prevent them from potentially overlapping. + if (firstItem->section()) + firstItem->setPosition(firstItem->position()); + for (int i=1; i < visibleItems.count(); ++i) { FxListItemSG *item = static_cast<FxListItemSG*>(visibleItems.at(i)); if (item->index >= fromModelIndex) { |