Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QML ListView: error when change width of delegate



  • Hi all,
    I want to create a list of item and the current item is bigger than others but i have an issue.
    When I flick the list so the first item is hidden and click on other item to change current index of listview, the contentX of listview is wrong. This only occur when the current index is 0
    More detail of what I do to test:

    • Current index is 0
    • Flick to the end of list and click on an item to change current index
    • Flick back to the begin and console.log(listView.contentX) => output 40 when it's suppose to output 0

    Anyone know how to fix this? I need to use contentX for another purpose.
    Here's my code:

    ListView{
            id:listView
            width: 1000; height:700
            orientation: ListView.Horizontal
            cacheBuffer: 20000
            spacing: 10
            model:15
            delegate: Rectangle{
                id:baseDele
                width: index == listView.currentIndex ? 120 : 100
                height: 500
                border.width: 1
                Text {
                    anchors.centerIn: parent
                    text:index
                }
                MouseArea{
                    anchors.fill: parent
                    onPressed: listView.currentIndex = index
                    onReleased: console.log(listView.contentX)
                    
                }
            }
        }
    

  • Qt Champions 2018

    You need to use originX too.

    listView.contentX + listView.originX should be 0.



  • I try what you suggest but originX and contentX is the same


Log in to reply