making hover work on list items

This commit is contained in:
talksik
2024-02-09 10:24:09 -08:00
parent f0201de219
commit fbaf2da3d7
+24 -2
View File
@@ -38,11 +38,33 @@ Window {
height: 1000
delegate: Item {
id: listItem
height: 20
width: 100
property bool hovered: false
required property string name
Text {
text: parent.name
Rectangle {
anchors.fill: parent
color: hovered ? "blue" : "transparent"
Text {
text: listItem.name
color: listItem.hovered ? "white" : "black"
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: listItem.hovered = true
onExited: listItem.hovered = false
onClicked: console.log("Clicked!")
}
transitions: Transition {
ColorAnimation { target: parent; property: "color"; duration: 200 }
}
}
}
}