Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Highlighted ListView item not unlighted when scrolling
QtWS25 Last Chance

Highlighted ListView item not unlighted when scrolling

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 917 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PhTe
    wrote on last edited by
    #1

    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: {
            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 the onExited and onDragChanged functions, but none of them are called.

    p3c0P 1 Reply Last reply
    0
    • P PhTe

      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: {
              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 the onExited and onDragChanged functions, but none of them are called.

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by p3c0
      #2

      @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
          }
      }
      

      157

      1 Reply Last reply
      0
      • P Offline
        P Offline
        PhTe
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved