fix: lazy list view spacing + debounce relayout

This commit is contained in:
2 * r + 2 * t 2026-04-03 18:14:49 +11:00
parent 20983ffa6e
commit ea776c20e0
2 changed files with 14 additions and 5 deletions

View file

@ -422,13 +422,15 @@ void LazyListView::relayout() {
qreal y = 0;
bool hasLayoutItem = false;
for (auto& record : m_layout) {
record.targetY = y;
const qreal layoutH = record.heightKnown ? record.height : effectiveEstimatedHeight();
if (layoutH > 0) {
if (hasLayoutItem)
y += m_spacing;
hasLayoutItem = true;
record.targetY = y;
y += layoutH;
} else {
record.targetY = y;
}
}
@ -653,10 +655,16 @@ LazyListView::DelegateEntry LazyListView::createDelegate(int modelIndex) {
if (wasKnown)
untrackHeight(oldH);
trackHeight(h);
// Relayout immediately so layoutHeight/contentHeight update
// synchronously for parent bindings, then polish for delegate sync.
relayout();
polish();
// Batch relayout: multiple height changes in the same event loop
// iteration are coalesced into a single relayout + polish.
if (!m_relayoutPending) {
m_relayoutPending = true;
QTimer::singleShot(0, this, [this] {
m_relayoutPending = false;
relayout();
polish();
});
}
}
return;
}

View file

@ -281,6 +281,7 @@ private:
int m_activeAnimations = 0;
bool m_componentComplete = false;
bool m_relayoutPending = false;
QSet<int> m_pendingAddAnimations;
QList<QMetaObject::Connection> m_modelConnections;