Highlight when scrolling through ListView



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

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.