2016-11-11 49 views
0

我有一個自定義模型,它從QAbstractItemModel繼承。它實現了一個雙深度列表(第一層有n個元素,每個元素有m個子元素)。我可以成功地將GridView的模型綁定到第一層。我將如何去綁定一個嵌套的ListView來顯示第二層元素?如何顯示分層表格

GridView { 
    model: myModel 
    delegate: ColumnLayout { 
     Text { text: "First layer" } 
     ListView { 
      model: // What do I put here? 
      delegate: Text { text: "Second layer" } 
     } 
    } 
} 
+0

[QML PathView中的SetRootIndex]的可能重複(http://stackoverflow.com/questions/27648701/setrootindex-in-qml-pathview) – BaCaRoZzo

回答

0

您可以使用DelegateModel。

DelegateModel有一個名爲rootIndex的屬性,您可以使用該屬性告訴ListView將模型的根移到其中一個子列表的開始位置。

ListView { 
    model: DelegateModel { 
     model: myModel 
     delegate: {...} 
     rootIndex: index 
    } 
} 

其中index是從您的GridView附加的指令,它指向您的子條目的父條目。