-
Bug
-
Resolution: Done
-
P2: Important
-
5.9.1
-
None
-
db321e74413ac088edaa209a57ad5147175df041 (qt/qtdeclarative/5.14)
When changing a GridView's model to an empty one, currentIndex and currentItem are changed to -1 and null, but no currentItemChanged or currentIndexChanged signal is emitted.
The following QML snippet demonstrates this:
Column {
Button {
text: "Add"
property int counter: 0
onClicked: {
var list = gridView.model;
list.push( counter );
gridView.model = list;
counter += 1;
}
}
Button {
text: "Remove"
enabled: gridView.currentItem !== null
onClicked: {
var list = gridView.model
list.splice( gridView.currentIndex, 1 );
gridView.model = list;
}
}
Button {
text: "Remove 2"
// NOTE This only works as gridView.count gets updated
enabled: ( gridView.currentIndex >= 0 ) &&
( gridView.currentIndex < gridView.count )
onClicked: {
var list = gridView.model
list.splice( gridView.currentIndex, 1 );
gridView.model = list;
}
}
GridView {
id: gridView
model: []
clip: true
width: 200
height: 200
onCountChanged: console.log("count changed", count)
onCurrentIndexChanged: console.log("currentIndex changed", currentIndex)
onCurrentItemChanged: console.log("currentItem changed", currentItem)
cellWidth: 50
cellHeight: 50
delegate: Rectangle {
width: 45
height: 45
color: (index === gridView.currentIndex) ? "red" : "green"
MouseArea {
anchors.fill: parent
onClicked: gridView.currentIndex = index
}
Text {
anchors.centerIn: parent
text: modelData
}
}
}
}
By pressing Add new items are added. When pressing Remove or Remove 2 items are removed again.
The expected behavior would be that when the last item got removed both Remove and Remove 2 become disabled and the change of count (to 0), currentIndex (to -1) and currentItem (to null) is logged to the console.
However currentIndex and currentItem don't signal their change and only Remove 2 gets disabled as it also binds to gridView.count.