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. QML ListView contentX is updated despite highlightFollowCurrentItem: false
Forum Update on Monday, May 27th 2025

QML ListView contentX is updated despite highlightFollowCurrentItem: false

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

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