From 7f88725023dd47579e6d18c97dd97ed8cd78a564 Mon Sep 17 00:00:00 2001 From: Ly-sec Date: Sun, 30 Nov 2025 19:48:43 +0100 Subject: [PATCH] NComboBox: fix clicking issue --- Widgets/NComboBox.qml | 45 +++++++++++++++++++++++++++++++++---------- Widgets/NListView.qml | 41 +++++++++++++++++++++++++++++++++------ 2 files changed, 70 insertions(+), 16 deletions(-) diff --git a/Widgets/NComboBox.qml b/Widgets/NComboBox.qml index 7fead277..b3e3bbf4 100644 --- a/Widgets/NComboBox.qml +++ b/Widgets/NComboBox.qml @@ -115,11 +115,31 @@ RowLayout { verticalPolicy: ScrollBar.AsNeeded delegate: ItemDelegate { - property var parentComboBox: combo // Reference to the ComboBox - property int itemIndex: index // Explicitly capture index - width: parentComboBox ? parentComboBox.width : 0 + property var parentComboBox: combo + property int itemIndex: index + width: ListView.view ? ListView.view.width : (parentComboBox ? parentComboBox.width - Style.marginM * 3 : 0) hoverEnabled: true highlighted: ListView.view.currentIndex === itemIndex + + property bool pendingClick: false + Timer { + id: clickRetryTimer + interval: 50 + repeat: false + onTriggered: { + if (parent.pendingClick && parent.ListView.view && !parent.ListView.view.flicking && !parent.ListView.view.moving) { + parent.pendingClick = false; + var item = root.getItem(parent.itemIndex); + if (item && item.key !== undefined && parent.parentComboBox) { + root.selected(item.key); + parent.parentComboBox.currentIndex = parent.itemIndex; + parent.parentComboBox.popup.close(); + } + } else if (parent.pendingClick) { + restart(); + } + } + } onHoveredChanged: { if (hovered) { @@ -128,16 +148,22 @@ RowLayout { } onClicked: { - var item = root.getItem(itemIndex); - if (item && item.key !== undefined && parentComboBox) { - root.selected(item.key); - parentComboBox.currentIndex = itemIndex; - parentComboBox.popup.close(); + if (ListView.view && (ListView.view.flicking || ListView.view.moving)) { + ListView.view.cancelFlick(); + pendingClick = true; + clickRetryTimer.start(); + } else { + var item = root.getItem(itemIndex); + if (item && item.key !== undefined && parentComboBox) { + root.selected(item.key); + parentComboBox.currentIndex = itemIndex; + parentComboBox.popup.close(); + } } } background: Rectangle { - width: parentComboBox ? parentComboBox.width - Style.marginM * 3 : 0 + anchors.fill: parent color: highlighted ? Color.mHover : Color.transparent radius: Style.radiusS Behavior on color { @@ -173,7 +199,6 @@ RowLayout { } } - // Update the currentIndex if the currentKey is changed externalyu Connections { target: root function onCurrentKeyChanged() { diff --git a/Widgets/NListView.qml b/Widgets/NListView.qml index a588d4fa..729fbd88 100644 --- a/Widgets/NListView.qml +++ b/Widgets/NListView.qml @@ -112,16 +112,45 @@ Item { ListView { id: listView anchors.fill: parent - - // Enable clipping to keep content within bounds + + anchors.rightMargin: root.verticalScrollBarActive ? root.handleWidth + 4 : 0 clip: true - - // Enable flickable for smooth scrolling boundsBehavior: Flickable.StopAtBounds + flickDeceleration: 1500 + + Timer { + id: scrollbarActiveTimer + interval: 150 + repeat: false + } + + WheelHandler { + id: wheelHandler + target: listView + acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad + + onWheel: function(event) { + if (listView.flicking || listView.moving) { + listView.cancelFlick(); + } + + var delta = event.pixelDelta.y !== 0 ? event.pixelDelta.y : (event.angleDelta.y / 8); + var newContentY = listView.contentY - delta; + newContentY = Math.max(0, Math.min(newContentY, listView.contentHeight - listView.height)); + listView.contentY = newContentY; + + if (listView.ScrollBar.vertical) { + listView.ScrollBar.vertical.active = true; + } + + scrollbarActiveTimer.restart(); + event.accepted = true; + } + } ScrollBar.vertical: ScrollBar { - parent: listView - x: listView.mirrored ? 0 : listView.width - width + parent: root // Position relative to root Item, not listView + x: listView.mirrored ? 0 : root.width - width y: 0 height: listView.height policy: root.verticalPolicy