[SOLVED] QML: QListView / QListModel force repainting listview / delegates
-
Hi,
i have a simple ListModel and ListView which displays the data.
The ListView has its own delegate which paints something on a Canvas.
I have a function declared from which i want to trigger a repaint of the listview (the delegates which paint on a canvas).
But nothing seems to trigger repainting the delegate. (onPaint from the canvas of the delegate is never called again).
i Tryed model.revert()
and listView.update...
Nothing triggers repainting ...Any ideas?
Greetings,
Nando -
Hi,
i solved it by setting the model to 0 and then set it again.
@
menueListView.model = 0;
menueListView.model = menueModel
@It works but i think it is not the best solution. Any ideas?
Greetings
-
I mean the ListView only update it self if needed like the model data has changed. What you did is reset the model so the list must be repaint it self and also the delegates. What's your reason to force an update because the model data are fix right? Animated delegates?
-
Hi,
i use this to realize a drop in menue.because i paint the delegates by myself i must trigger somehow the repaint operation after selection changes.
if i click on a listview row i save the index and closes the menue....(and load the stuff for the selected row.)later when repopening the menue the menue must be painted with the new index selected...
so i must somehow trigger the list view to repaint...Greetings
-
Hmmm, but you don't need to repaint the whole listview you only need to repaint the canvas of the actual selected and the old selected item so maybe something like this can work:
@
ListView {
id: list
model: model
anchors.fill: parent
delegate: Canvas {
anchors.left: parent.left
anchors.right: parent.right
height: 30
onPaint: {
var ctx = getContext("2d")
ctx.fillStyle = 'green'
if (list.currentIndex == index) {
ctx.fillStyle = 'red'
}
ctx.fillRect(0, 0, this.width, this.height)
}
MouseArea {
anchors.fill: parent
onClicked: {
if (list.currentIndex != -1) {
list.currentItem.requestPaint()
}
list.currentIndex = index
list.currentItem.requestPaint()
}
}
}
}
@It's totaly dirty and an example but i hope i have understand what you want.
-
Please add solved to your thread title