I have a TableView and would like to highlight the column that the mouse is over.
I can do the visual part by drawing a rectangle in the itemDelegate.
What I am struggling with is getting the column index the mouse is over.
I found the function tableView.__listView.columnAt() but it always returns -1
Here is the relevant part of my tableView qml...
property int mouseColumn: 0
itemDelegate: Item {
id: item
Rectangle {
anchors.fill: parent
color: "Green"
visible: {
// highlight the column the mouse is over
if(styleData.column == tableView.mouseColumn)
true
else
false
}
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
onPositionChanged: {
var coordinates = item.mapToItem(tableView, mouse.x, mouse.y)
// TODO: how to find column index at coordinates, columnAt always returns -1 for some reason
tableView.mouseColumn = tableView.__listView.columnAt(coordinates.x)
}
}
}
property int mouseColumn: 0
itemDelegate: Item {
id: item
Rectangle {
anchors.fill: parent
color: "Green"
visible: {
// highlight the column the mouse is over
if(styleData.column == tableView.mouseColumn)
true
else
false
}
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
onPositionChanged: {
var coordinates = item.mapToItem(tableView, mouse.x, mouse.y)
// TODO: how to find column index at coordinates, columnAt always returns -1 for some reason
tableView.mouseColumn = tableView.__listView.columnAt(coordinates.x)
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks