2

qml にネストされたリストビューを含むリストビューがあります。ネストされたリストビュー デリゲートで親リストビュー インデックスのインデックスを取得するにはどうすればよいですか?

コードサンプル:

ListView {
        id: listView
        anchors.fill: parent
        delegate: delegate
        model: myModel
    }

    Component {
        id: delegate
        Item {
            id: recipe
            width: listView.width
            height: 120


            Column {

                   // some text fields
                    ListView {
                        id: listView1
                        width: listView.width
                        height: 50
                        delegate: nextLevelDelegate
                        model: nextLevelList
                    }

                }
        }
    }

    Component {
        id: nextLevelDelegate
        Item{
                                        width: listView1.width
                                        height: 20
                                        Rectangle {
                                            id: background2
                                            x: 2; y: 2; width: parent.width - x*2; height: parent.height - y*2
                                            color: "lightgray"
                                            border.color: "gray"
                                            radius: 5
                                        }
                                        Text {
                                            anchors.fill: parent
                                            id:nextLevelButton
                                            horizontalAlignment:Text.AlignHCenter
                                            text: modelData
                                        }
                                        MouseArea
                                        {
                                          anchors.fill: parent
                                          id: mouseArea
                                          onClicked: {
                                             window.buttonPressed(nextLevelButton.text,listView.currentIndex);//I need parent index here for calling c++ method with it
                                          }
                                        }
                                    }

    }
4

2 に答える 2

4

親リストビューのインデックスを別のプロパティに割り当てて、シャドウされないようにします。

ListView {
   id: listView1
   property int parentIndex: index
   width: listView.width
   height: 50
   delegate: nextLevelDelegate
   model: nextLevelList

}

parentIndexnextLevelDelegateとしてで利用可能になりますlistView1.parentIndex

于 2012-11-14T21:38:27.067 に答える