Model view controller 是否可以使用QML替换视图中的委托?

Model view controller 是否可以使用QML替换视图中的委托?,model-view-controller,qt,delegates,model,qml,Model View Controller,Qt,Delegates,Model,Qml,比如说 ListView { id: listView anchors.fill: parent anchors.margins: 20 model: myModel delegate: myDelegate highlightFollowsCurrentItem: true focus: true ListModel { id: myModel ListElement {

比如说

 ListView {
     id: listView
     anchors.fill: parent
     anchors.margins: 20
     model: myModel
     delegate: myDelegate
     highlightFollowsCurrentItem: true
     focus: true
     ListModel {
         id: myModel

         ListElement {
             name: "Apple"; cost: 2.45
             attributes: [
                 ListElement { description: "Core" },
                 ListElement { description: "Deciduous" }
             ]
         isOnMouse: false
     }
 }
我使用myDelegate作为任何模型的默认值,但如果单击其中一个项,我将不为该项使用另一个委托,仅为该项


有可能吗?

如果您使用QML元素作为委托,那么您应该能够更改其
源组件
,从而有效地更改单个项目的委托。

在主项目中定义:

property boolean isItem:false
在您的委托书中:

onClicked:isItem=index==myIndex
其中myIndex描述您的特殊项目

在listView集合中:

delegate: isItem? otherDel : myDelegate

我已经回答了一个类似的问题:。这可能会有所帮助。这并不能回答问题,因为它会更改所有项目的委托,而不仅仅是单击项目的委托。