Nominate our 2022 Qt Champions!

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 highlighting

    MouseArea {
        anchors.fill: parent
        hoverEnabled: true
        onPressed: {
        onReleased: {
            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 the onExited and onDragChanged functions, but none of them are called.

  • Moderators

    @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 use pressed to achieve the above effect.

    delegate: Rectangle {
        width: 200
        height: 40
        color: mouseArea.pressed ? "#ABC" : "transparent"
        MouseArea {
            id: mouseArea
            anchors.fill: parent

  • I used the pressed property like you wrote in the short example.

Log in to reply