QML ListView contentX is updated despite highlightFollowCurrentItem: false



  • Hi,

    I want to make ListView, which would ignore currentIndex/currentItem changes and would keep specified content position unchanged, no matter what.
    I've used highlightFollowsCurrentItem: false for that (see example below). And when you increment current index (e.g. by pressing 'down') contentX remains unchanged, even if current item is no longer visible. But if you change contentX manually so it's not in the beginning (press 'space') and start decrementing current index - contentX will be updated once current item is no longer visible. Without animation (see Behavior on contentX below). Is that expected behavior? I couldn't find documentation which describes this behaviour.
    I'm using Qt 5.9.4

    import QtQuick 2.9
    import QtQuick.Window 2.2
    
    Window {
    	visible: true
    	width: 640
    	height: 480
    	title: qsTr("Hello World")
    
    	ListView {
    		id: listView
    		focus: true
    		anchors.fill: parent
    		orientation: ListView.Vertical
    		model: 20
    		spacing: 10
    
    		keyNavigationEnabled: true
    
    		highlightFollowsCurrentItem: false
    
    		delegate: Rectangle {
    			height: 100
    			width: listView.width
    			color: ListView.isCurrentItem ? 'green' : 'orange'
    
    			Behavior on color { ColorAnimation {} }
    
    			Text {
    				anchors.centerIn: parent
    				text: index
    			}
    		}
    
    		Behavior on contentX { NumberAnimation {} }
    
    		Keys.onPressed: {
    			if (event.key === Qt.Key_Space) {
    				contentY = contentHeight - height;
    				event.accepted = true;
    				return;
    			}
    		}
    	}
    }
    

Log in to reply
 

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