0

例如

 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 作为任何模型的默认值,但是如果单击其中一个项目,我想为该项目使用另一个委托,仅用于该项目。

可能吗?

4

2 回答 2

1

如果您使用 QMLLoader元素作为您的委托,那么您应该能够更改它的sourceor sourceComponent,从而有效地更改单个项目的委托。

于 2011-04-06T23:48:43.617 回答
1

在您的主要项目中定义:

property boolean isItem:false

在您的代表中:

onClicked: isItem=index==myIndex myIndex 描述您的特殊项目的位置

在 listView 集中:

delegate: isItem? otherDel : myDelegate
于 2011-10-21T07:30:14.587 回答