
import QtQuick 21
import QtQuickWindow 21
import QtQuickControls 12
Window {
visible: true
width: 360
height: 360
Rectangle {
width: 200; height: 200
ListModel {
id: fruitModel
property string language: "en"
ListElement {
name: "Apple"
cost: 245
}
ListElement {
name: "Orange"
cost: 325
}
ListElement {
name: "Banana"
cost: 195
}
}
ListModel {
id: fruitModel2
property string language: "en"
ListElement {
name: "A"
cost: 245
}
ListElement {
name: "B"
cost: 325
}
ListElement {
name: "C"
cost: 195
}
ListElement {
name: "D"
cost: 195
}
}
Component {
id: fruitDelegate
Item{
Row {
Label{
objectName: "lblName" + index + "1"
text: " Fruit: " + name
}
Label{
objectName: "lblName" + index + "2"
text: " Fruit: " + name
}
}
}
}
ListView {
id:list
property color fruit_color: "green"
model: fruitModel
delegate: fruitDelegate
anchorsfill: parent
}
Rectangle {
x:200
width: 50; height: 50
color: "red"
MouseArea{
anchorsfill: parent
onClicked: {
listmodel = fruitModel2
consolelog(listchildren[0]children[3]children[0]children[0]objectName)
consolelog(listchildren[0]children[2]children[0]children[1]objectName)
}
}
}
}
}
如果是一整行的数据,假设现在一行有4个数据吧。
如果要遍历的话用foreach来实现
int
i=0;
StreamWriter
SW=new
StreamWriter(@"D:\testtxt",true);
foreach(ListViewItem
LVI
in
thisListView1Items
)
{
SWWrite(LVISubItem[0]text+"|");
SWWrite(LVISubItem[1]text+"|");
SWWrite(LVISubItem[2]text+"|");
SWWriteLine(LVISubItem[3]text);
}
SWClose();
上面是简单的实现将LivsView中的数据写入一个testtxt的文本文档中,每一行ListView的数据用
|
隔开,每写完一行后,转入下一行进行写数据,知道遍历完整个ListView的数据,此外当一行的数据很多的时候,也可以用SubItemsCounts来得到它的个数,并用循环分别读取,由于为了演示的方便,就直接列出了4个
你是想在LISTVIEW中怎么选中是用鼠标选中的时候获取值吗 答案补充 使用ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)事件,当选项发生改变的时候会进入这个事件,然后object sender把这个对象强制转换成ListViewItem,这个对象就是你选中的对象然后从这个对象里面取你想要的值 答案补充 你在属性里面找他的事件,双击进去就在里面写代码了那2个参数不需要你给
以上就是关于qt 如何从listview中获取选中的数据全部的内容,包括:qt 如何从listview中获取选中的数据、如何获取listview行值、如何从C#中获取ListView中选中某一行某一列的值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)