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

ListView indexAt Issue



  • Hi all,
    I meet an issue with listView indexAt when LayoutMirroring.enabled: true

    LayoutMirroring.enabled: true -> indexAt return -1

    Do you have an idea how i can resolve this ?

    (If I change LayoutMirroring.enabled: false , it is OK)

    import QtQuick 2.12
    import QtQuick.Window 2.12

    Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    LayoutMirroring.enabled: true
    LayoutMirroring.childrenInherit: true
    property alias listView: listView
    
    
    ListView { // PageDots
        id: listView
        width: 250; height: 100
        snapMode: ListView.SnapOneItem
        orientation: Qt.Horizontal
    
        model: 3
        delegate: Item {
            width: 50; height: 50
            Text {
                text: index
                font.pixelSize: 0.9 * listView.height
                anchors.centerIn: parent
            }
    
        }
    
    }
    MouseArea {
        id: mouseArea
        anchors.fill: parent
        onClicked: {
            console.log("indexAt(0) : "+listView.indexAt(0,0));
            console.log("indexAt(200)  : "+listView.indexAt(200,0));
            console.log("indexAt(400) : "+listView.indexAt(400,0));
            console.log("indexAt(600) : "+listView.indexAt(600,0));
        }
    }
    

    }


Log in to reply