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

View file

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