2011-04-06 20 views
0

例如有任何可能使用QML替換視圖中的委託?

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爲默認任何模型,但如果被點擊的項目之一,我whant使用另一種委託這個項目,只是爲這個項目。

可能嗎?

+0

我我回答了一個類似的問題:http://stackoverflow.com/questions/24784706/selecting-delegates-dependi NG-的屬性。也許它有幫助。 – mhcuervo 2014-07-17 16:12:57

回答

1

如果您使用QML Loader元素作爲您的代理人,那麼您應該能夠更改其或sourceComponent,從而有效地更改您的單個項目的委託。

1

在你的主項定義:

property boolean isItem:false 
在委託化妝

onClicked: isItem=index==myIndex其中myIndex在ListView集合descripe您的特殊項目

delegate: isItem? otherDel : myDelegate 
+0

這不會回答問題,因爲它會更改所有項目的委託,而不僅僅是單擊項目的委託。 – 2016-09-27 21:42:39