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. Highlight when scrolling through ListView
Qt 6.11 is out! See what's new in the release blog

Highlight when scrolling through ListView

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 449 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.
  • N Offline
    N Offline
    nathan_dev
    wrote on last edited by nathan_dev
    #1

    I am using QtQuick 2.3 and Qt 5.6

    I am having issues with how highlight moves when scrolling through my ListView and updating the currentItem. Currently I have a ListView nested in a ScrollView and the delegate each have a mouse area that updates currentIndex onEnter. When I scroll, the highlight disappears. What would the best way to implement having the highlight stay under mouse cursor while scrolling?
    Here is some relevant sections for how I am organizing it.

    	Component {
    		id: nameDelegate
    		Rectangle {
    			color: "transparent"
    			height: 28
    			anchors.left: parent.left 
    			anchors.right: parent.right 
    
    			MouseArea {
    				id: mouseArea
    				hoverEnabled: true
    				cursorShape: Qt.PointingHandCursor
    				anchors.fill: parent
    				onEntered: listView.currentIndex = index;
                                    onExited: listView.currentIndex = -1;
    			      }
    
    		        }
               }
    
    	Component {
    		id: categoryDelegate
    		Rectangle {
    			color: "white"
    			height: 30
    			anchors.left: parent.left
    			anchors.right: parent.right
    			Text {
    				id: categoryText
    				anchors.verticalCenter: parent.verticalCenter
    				anchors.left: parent.left
    				anchors.leftMargin: 12
    				font.pixelSize: 14
    				color: "gray"
    				text: section
    			}
    
    		}
    	}
    
    	ScrollView {
                    id: scrollView
    		anchors.top: searchBox.bottom	    
    	        anchors.left: parent.left
    	        anchors.right: parent.right
                    anchors.bottom: parent.bottom
    
    	    ListView {
    	    	id: listView	    
    	    	anchors.fill: parent
    	    	model: insertObjectListModel
    	    	delegate: nameDelegate
                    highlightFollowsCurrentItem: true
    		highlight: Rectangle {
    			id: highlightBar
    	    		width: listView.width
    	    		height: 28
    	    	}
    
    	    	section {
    	    		property: "category"
    	    		delegate: categoryDelegate
    	    	}
    	    }
    	}
    }
    
    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