NComboBox: fix clicking issue

This commit is contained in:
Ly-sec
2025-11-30 19:48:43 +01:00
parent 087c9b4ced
commit 7f88725023
2 changed files with 70 additions and 16 deletions

View File

@@ -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() {

View File

@@ -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