qt 如何从listview中获取选中的数据

qt 如何从listview中获取选中的数据,第1张

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)

}

}

}

}

}

想要得到id首先你要先存入listview显示的数据中 例如 simpleAdapter中的data,在显示的时候需要把你想要的数据利用map存入data中,然后通过HashMap<String, Object> data = (HashMap<String, Object>)listviewgetItemAtPosition(arg2);来得到数据,之后 你就可以从data中得到你想要的数据了 。 希望这对你有所帮助~~

以上就是关于qt 如何从listview中获取选中的数据全部的内容,包括:qt 如何从listview中获取选中的数据、android编程,选中listview的一行并获取此行显示的数据在数据库中的id、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/9281364.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-26
下一篇 2023-04-26

发表评论

登录后才能评论

评论列表(0条)

保存