TableView {
id: testTable
rowSpacing: 0
columnSpacing: 8
clip: true
anchors.topMargin: 2
boundsBehavior: Flickable.OvershootBounds
columnWidthProvider: function(column) {
if(column === 0) return 50;
else if(column === 1) return 580;
else return 60;
}
model: tableModel
delegate: Rectangle {
id: cellContainer
implicitWidth: 100
implicitHeight: 42
Text {
anchors.fill: parent
verticalAlignment: Qt.AlignVCenter
horizontalAlignment: column === 1 ? Qt.AlignLeft : Qt.AlignHCenter
font.family: outfitRegular.name
font.pixelSize: 14
text: {
var col = model.columnNo
if(col === 0)
return model.index
else if(col === 1)
return model.name
else
return model.status
}
}
MouseArea {
id: mouse
anchors.fill: parent
onClicked: {
console.log(model.index)
}
}
}
}
I tried coloring the delegate in the mouseArea's onClick method, but as expected, it only changes the cell color and not the entire row's color. I'm wondering what I should do to achieve this. I have found older code on stack overflow but none of them works on the newer version of TableView.
I am new to QML and any input regarding this would be helpful.
Just to illustrate this idea:
Or in more generic way you can set
as described here, you can also use SelectionRectangle etc.