Lunatik
Lunatik

Reputation: 189

There are any possibilities to replace delegate in the view using QML?

For example

 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
     }
 }

I use myDelegate as default for any model, but if one of the item is clicked i whant to use another delegate for this item, only for this item.

Is it possible?

Upvotes: 0

Views: 1715

Answers (2)

Thorbjørn Lindeijer
Thorbjørn Lindeijer

Reputation: 2112

If you use the QML Loader element as your delegate, then you should be able to change its source or sourceComponent, effectively changing your delegate for a single item.

Upvotes: 1

h_kassem
h_kassem

Reputation: 450

In your main item define:

property boolean isItem:false

in your delegate make:

onClicked: isItem=index==myIndex where myIndex descripe your special item

in the listView set :

delegate: isItem? otherDel : myDelegate

Upvotes: 1

Related Questions