简体   繁体   English

在ListView QML / Qt中访问数据(选定)

[英]Access Data (Selected) in a ListView QML/Qt

I'm accessing a XML page (online) via a XmlListModel and displaying the data using a ListView delegate (Row). 我正在通过XmlListModel访问XML页面(在线),并使用ListView委托(行)显示数据。

Once the Listview display the data (Xml file always only contain one "record"), i want a separate label to display one of the node's data (selected row)? 一旦Listview显示数据(Xml文件始终只包含一个“记录”),我是否希望使用单独的标签显示节点数据之一(选定的行)? Any guidance on this matter is appreciated. 对此问题的任何指导表示赞赏。

My Listview: 我的列表视图:

ListView {
id: viweID
model: modelID
delegate: Row {
    id:rowID
    spacing: 10
    Text {
        id: fnameId
        text: FName
         }
    Text {
        id:lnameID
        text: LName
    }
}

Thank you 谢谢

The ListView can be accessed either in terms of its items or by visiting its underlying model (see the documentation for further details). ListView可以按其项进行访问,也可以通过访问其基础模型进行访问(有关更多详细信息,请参见文档 )。

It looks to me that you want to visit the former, for it already contains all the data that have to be shown on your separated panel. 在我看来,您想访问前者,因为它已经包含了必须在单独面板上显示的所有数据。
To do that you can rely on the currentItem property and the signals onCurrentItemChanged / onCurrentIndexChanged . 为此,您可以依赖currentItem属性和onCurrentItemChanged / onCurrentIndexChanged信号。
It's a matter of exposing the desired properties from the delegate object to be able to read them and set them on the other panel. 可以从委托对象中公开所需的属性,以便能够读取它们并在另一个面板上进行设置。
See here for further details on how to expose those properties. 有关如何公开这些属性的更多详细信息,请参见此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM