ListView And The Items
-
Hi, I have a problem with ListView and getting and setting the view's item's property, here is the code:
import QtQuick 2.5
Item {
id: root
clip: trueproperty color mainColor property color textColor property color greyTextColor property color specialMainColor property color specialTextColor property color invertMainColor property color invertTextColor property color pressedColor property color hoverColor property string playIcon property int activeRow: MLoader.activeQueueRow ListView{ id: listView anchors.fill: parent model: MLoader.queueRowCount delegate: QueueDelegate{ mainColor: root.mainColor textColor: root.textColor invertMainColor: root.invertMainColor invertTextColor: root.invertTextColor greyTextColor: root.greyTextColor pressedColor: root.pressedColor hoverColor: root.hoverColor playIcon: root.playIcon width: root.width height: textHeight + root.height/12 delegateIndex: index delegatePlayState: false title: MLoader.queueValue(index,0) artist: MLoader.queueValue(index,1) artwotk: "file://" + MLoader.queueValue(index,3) } } onActiveRowChanged: { listView.model.get(activeRow).delegatePlayState = true }
}
I want to change an item's property when a signal is activated but the code doesn't work. what should I do?
-
@shahriar25 Does the model have
delegatePlayState
? -
Hi @p3c0
the model is a cpp function (Q_PROPERTY) that returns an integer -
@shahriar25
If you want to change property of Listview currentItem, thenonCurrentItemChanged(){ currentItem.delegatePlayState = true; }
-
@shahriar25
To update a delegate using a model you will need to bind the properties defined in the model with the delegate. Then you need to modify that particular property in the model and notify the delegate about the changes usingdataChanged
.But in your case you don't have
QAbstractItemModel
based model so above solution wont work. @medyakovvit's answer should be sufficient. -
@medyakovvit said:
@shahriar25
If you want to change property of Listview currentItem, thenonCurrentItemChanged(){ currentItem.delegatePlayState = true; }
Or if you want to set currentItem.delegatePlayState = true and set previous currentItem.delegatePlayState = false, then you can try to write in Listview delegate:
delegate: QueueDelegate{ // bla bla bla delegatePlayState: Listview.isCurrentItem // bla bla bla }