Highlighted ListView item not unlighted when scrolling
-
Sorry for this confusing thread title.
I have a qml ListView which should highlight the item as long as the mouse is pressed. I have created an item delegate with a MouseArea in it which handles the highlightingMouseArea { anchors.fill: parent hoverEnabled: true onPressed: { parent.color="#ABC"; } onReleased: { parent.color="transparent"; myList.currentIndex = index; } }
This works so far, if i press and release the button on the same listview item. But if i press the mouse button, hold it and then move the mouse to scroll in the list, the
onReleased
event in the mousearea is not called and so the color is never set back to transparent.
Does anyone know a solution to reset the color of the item if the listview is scrolled.
I already tried theonExited
andonDragChanged
functions, but none of them are called. -
Sorry for this confusing thread title.
I have a qml ListView which should highlight the item as long as the mouse is pressed. I have created an item delegate with a MouseArea in it which handles the highlightingMouseArea { anchors.fill: parent hoverEnabled: true onPressed: { parent.color="#ABC"; } onReleased: { parent.color="transparent"; myList.currentIndex = index; } }
This works so far, if i press and release the button on the same listview item. But if i press the mouse button, hold it and then move the mouse to scroll in the list, the
onReleased
event in the mousearea is not called and so the color is never set back to transparent.
Does anyone know a solution to reset the color of the item if the listview is scrolled.
I already tried theonExited
andonDragChanged
functions, but none of them are called.@PhTe The problem is as soon as the scrolling starts the mouse events gets canceled. You can either use
onCancelled
handler in addition to your above code to reset the color or usepressed
to achieve the above effect.delegate: Rectangle { width: 200 height: 40 color: mouseArea.pressed ? "#ABC" : "transparent" MouseArea { id: mouseArea anchors.fill: parent } }