各行に InputText を含む Listview が必要です。ユースケースは、行ごとに数量を変更できるアイテムのカートです。
以下のコードでは、Listview はラベルとテキスト ボックスを横に表示しています。
問題は、すべてのテキスト ボックスの ID が同じになることです。そのため、最後に変更されたテキスト ボックスの値に基づいて、すべてのテキスト ボックスの値が変更されます。例: 最初のアイテムに 10、2 番目のアイテムに 12 を入力すると、最初のアイテムの数量も 12 に変更されます。
onEnterはデモンストレーション専用です。今後はonFocusChangedになる可能性があります。
ListView {
id:list
model: fruitModel
x:10
y:10
width: parent.width-20
height: parent.height-20
clip:true
anchors.fill: parent
delegate: Row {
width: parent.width
height:30
Item
{
property variant myData: model
property alias value: text.text
Text {
id:text
width: parent.width
height: 30
text:name
}
InputText {
id: inp_box
text:qty
width:100
height:22
anchors.verticalCenterOffset: 15
anchors.horizontalCenterOffset:250
focus: true
onEnter: {
editQty(inp_box.text);
}
}
}
}
focus: true
snapMode: ListView.SnapOneItem
ScrollBar {
flickable: list
vertical: true
hideScrollBarsWhenStopped:false
}
}