• 4315阅读
  • 0回复

[提问]QML ObjectModel嵌套使用后index改变 [复制链接]

上一主题 下一主题
离线charles_gz
 

只看楼主 倒序阅读 楼主  发表于: 2015-06-25
各位大牛:
       在使用中发现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
快速回复
限100 字节
 
上一个 下一个