From 944ade18409e56152a776298e43bf5e9d5de5c41 Mon Sep 17 00:00:00 2001 From: yeshanshan Date: Fri, 27 Nov 2026 18:17:21 +0800 Subject: [PATCH] fix: handle zero-height content in arrow list view MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Add hasDelegate property to track if any delegate has been realized 2. Update sizedHeight logic to treat zero content height as valid when delegates exist 3. Remove temporary viewport fallback in ComboBox popup implicitHeight 4. Set hasDelegate flag during refreshContentItemWidth iteration The previous logic assumed contentHeight == 0 meant delegates weren't realized yet, causing a fallback viewport height. When delegates exist but measure zero height, this produced incorrect popup sizing. Tracking delegate realization explicitly distinguishes "not yet realized" from "realized with zero height". Influence: 1. Test ComboBox popup with empty model - should show appropriate minimum height 2. Test ComboBox popup with single item - verify no double-height gap 3. Test ComboBox popup with items having zero-height delegates 4. Verify ArrowListView sizing with various item counts 5. Test popup height recalculation when model changes dynamically 6. Verify popup renders correctly when delegates become visible fix: 修复箭头列表视图中零高度内容的处理 1. 添加 hasDelegate 属性以跟踪是否已实现任何委托 2. 更新 sizedHeight 逻辑,当存在委托时将零内容高度视为有效 3. 移除 ComboBox 弹出层 implicitHeight 中的临时视口回退逻辑 4. 在 refreshContentItemWidth 迭代期间设置 hasDelegate 标志 之前的逻辑假设 contentHeight == 0 意味着委托尚未实现,导致回退到视口高 度。当委托存在但测量高度为零时,这会导致弹出层尺寸错误。显式跟踪委托实现 状态可区分“尚未实现”和“已实现但高度为零”。 Influence: 1. 测试空模型的 ComboBox 弹出层 - 应显示适当的最小高度 2. 测试单条目的 ComboBox 弹出层 - 验证无双倍高度间隙 3. 测试委托高度为零的 ComboBox 弹出层 4. 验证不同条目数量下 ArrowListView 的尺寸 5. 测试模型动态变化时弹出层高度的重新计算 6. 验证委托变为可见时弹出层的正确渲染 Log: Fixed ComboBox popup sizing when content has zero measured height PMS: BUG-380893 --- qt6/src/qml/ArrowListView.qml | 11 +++++++++-- qt6/src/qml/ComboBox.qml | 4 +--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/qt6/src/qml/ArrowListView.qml b/qt6/src/qml/ArrowListView.qml index eb2e848a..7aecf42a 100644 --- a/qt6/src/qml/ArrowListView.qml +++ b/qt6/src/qml/ArrowListView.qml @@ -23,7 +23,8 @@ FocusScope { readonly property real sizedHeight: { if (itemsView.count === 0) return 0 - if (itemsView.contentHeight > 0) + // Once a delegate exists, zero is a valid measured content height. + if (itemsView.contentHeight > 0 || itemsView.hasDelegate) return implicitHeight const arrowStrips = itemsView.count > maxVisibleItems ? 2 * (DS.Style.arrowListView.stepButtonIconSize.height + contentLayout.spacing) : 0 @@ -57,6 +58,7 @@ FocusScope { ListView { id: itemsView property real itemMaxWidth: 0 + property bool hasDelegate: false clip: true Layout.fillWidth: true Layout.fillHeight: true @@ -98,9 +100,13 @@ FocusScope { function refreshContentItemWidth() { var maxWidth = itemMaxWidth + var foundDelegate = false for (var i = 0; i < itemsView.count; ++i) { var item = itemsView.itemAtIndex(i) - if (!item || !item.visible) + if (!item) + continue + foundDelegate = true + if (!item.visible) continue item.width = itemsView.width if (control._measuredRowHeight <= 0 && item.height > 0) @@ -108,6 +114,7 @@ FocusScope { if (item.implicitWidth > maxWidth) maxWidth = item.implicitWidth } + hasDelegate = foundDelegate itemMaxWidth = maxWidth } } diff --git a/qt6/src/qml/ComboBox.qml b/qt6/src/qml/ComboBox.qml index 7d61c936..48302dcd 100644 --- a/qt6/src/qml/ComboBox.qml +++ b/qt6/src/qml/ComboBox.qml @@ -172,9 +172,7 @@ T.ComboBox { rightMargin: DS.Style.popup.margin palette: control.palette implicitWidth: control.flat ? Math.max(contentItem.implicitWidth + leftPadding + rightPadding, control.width) : control.width - // 60 is a temporary viewport so the list can realize one row and be measured. - implicitHeight: (contentItem.sizedHeight > 0 ? contentItem.sizedHeight : 2 * DS.Style.arrowListView.itemHeight) - + topPadding + bottomPadding + implicitHeight: contentItem.sizedHeight + topPadding + bottomPadding onClosed: control.isInteractingWithContent = false Connections { target: control