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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了qt 如何从listview中获取选中的数据相关的知识,希望对你有一定的参考价值。

如标题

参考技术A import QtQuick 2.1
import QtQuick.Window 2.1
import QtQuick.Controls 1.2
Window
visible: true
width: 360
height: 360

Rectangle
width: 200; height: 200

ListModel
id: fruitModel
property string language: "en"
ListElement
name: "Apple"
cost: 2.45

ListElement
name: "Orange"
cost: 3.25

ListElement
name: "Banana"
cost: 1.95



ListModel
id: fruitModel2
property string language: "en"
ListElement
name: "A"
cost: 2.45

ListElement
name: "B"
cost: 3.25

ListElement
name: "C"
cost: 1.95

ListElement
name: "D"
cost: 1.95



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
anchors.fill: parent


Rectangle
x:200
width: 50; height: 50
color: "red"
MouseArea
anchors.fill: parent
onClicked:
list.model = fruitModel2
console.log(list.children[0].children[3].children[0].children[0].objectName)
console.log(list.children[0].children[2].children[0].children[1].objectName)




以上是关于qt 如何从listview中获取选中的数据的主要内容,如果未能解决你的问题,请参考以下文章

如何从C#中获取ListView中选中某一行某一列的值

android listview中如何将获取来的数据添加至listview尾部

C# 如何获取listview里面当前选中的item

listview 里有存在radiogroup,如何获得其选中的值?

如何获取listview的item中的内容

如何检索名称 | Listview中多个选中项目的值对?