各位大牛:
在使用中发现ObjectModel嵌套使用会导致ListView的index默认显示为最后一页,比如下面的代码:
import QtQuick 2.2import QtQuick.Controls 1.1import QtQuick.Controls.Styles 1.2import QtQml.Models 2.1
ApplicationWindow { visible: true width: 640 height: 480 title: qsTr("Hello World")
ObjectModel{ id:oneModel Rectangle{ width: listView.width - 20 height: listView.height -20 color: "black"
ObjectModel{ id:twoModel Rectangle{ width: listView2.width height: listView2.height color: "red" } Rectangle{ width: listView2.width height: listView2.height color: "yellow" } }
ListView{ id:listView2 anchors.fill: parent orientation: ListView.Horizontal model:twoModel }
} Rectangle{ width: listView.width height: listView.height color: "green" } }
ListView{ id:listView anchors.fill: parent model:oneModel }}程序启动后每个ListView显示的都是model的最后一个item