From 86a432fe5ebf07878da250f8c424b114824c7df2 Mon Sep 17 00:00:00 2001 From: loner <2788892716@qq.com> Date: Tue, 21 Oct 2025 22:37:18 +0800 Subject: [PATCH] fix(NComboBox): Improve delegate robustness --- Widgets/NComboBox.qml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Widgets/NComboBox.qml b/Widgets/NComboBox.qml index 00f29bb1..1a626bed 100644 --- a/Widgets/NComboBox.qml +++ b/Widgets/NComboBox.qml @@ -124,27 +124,29 @@ RowLayout { verticalPolicy: ScrollBar.AsNeeded delegate: ItemDelegate { - width: combo.width + property var parentComboBox: combo // Reference to the ComboBox + property int itemIndex: index // Explicitly capture index + width: parentComboBox ? parentComboBox.width : 0 hoverEnabled: true - highlighted: ListView.view.currentIndex === index + highlighted: ListView.view.currentIndex === itemIndex onHoveredChanged: { if (hovered) { - ListView.view.currentIndex = index + ListView.view.currentIndex = itemIndex } } onClicked: { - var item = root.getItem(index) - if (item && item.key !== undefined) { + var item = root.getItem(itemIndex) + if (item && item.key !== undefined && parentComboBox) { root.selected(item.key) - combo.currentIndex = index - combo.popup.close() + parentComboBox.currentIndex = itemIndex + parentComboBox.popup.close() } } background: Rectangle { - width: combo.width - Style.marginM * 3 + width: parentComboBox ? parentComboBox.width - Style.marginM * 3 : 0 color: highlighted ? Color.mTertiary : Color.transparent radius: Style.radiusS Behavior on color {