[英]QML Gridview with InputText
我需要在每行上都带有InputText的Listview。 用例是一个购物车,其中每行可以更改数量。
使用以下代码,Listview呈现带有一个标签和一个文本框的旁边。
问题是,所有文本框都将具有相同的ID,因此,所有文本框值都将根据上一次更改的文本框值进行更改。 例如:如果我为第一项输入10,为第二项输入12,则即使第一项的数量也变为12。
is only for demonstration. 仅用于演示。 going forward: 将来可能是 :
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
}
}
您应该扩展editQty
函数,以将fruitModel
中已编辑条目的索引作为附加参数。 当前条目的索引在列表视图的委托中作为index
。 用这种方式, editQty
没有机会知道要更改哪个条目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.