TableView
only allow to select rows by default, but you can override the selection behavior by customizing its cell delegate (itemDelegate
).
First you'll have to disable the default selection behavior with :
selectionMode: SelectionMode.NoSelection
Then in the itemDelegate
you can do something like that :
itemDelegate: Item {
property bool isSelected: false
// When user clicks on a cell, turn the isSelected flag on
MouseArea {
anchors.fill: parent
onClicked: isSelected = !isSelected
}
Text {
anchors.verticalCenter: parent.verticalCenter
// If this cell is selected, color the text in blue
color: isSelected ? "blue" : "black"
text: styleData.value
}
}
Be careful as the signals emitted by your TableView
will not work as your cells are accepting mouse events. But of course you can implement them easily if you need them.