Important: Please read the Qt Code of Conduct -

[solved] ListView.positionViewAtIndex() is not working

  • Hi,

    calling patientList.positionViewAtIndex(idx, ListView.Beginning) on ListView shown below neither scrolls the view nor prints any QML error in console. The same is true for setting currentIndex.

        ListView {
            id: patientList
            anchors.fill: parent
            property int itemHeight: 14 * mm
            clip: true
            maximumFlickVelocity: 9999
            model: SqlQueryModel {
                id: patientsModel
                query: "SELECT patient_id, name, surname, birth_date, last_visit_date " +
                       "FROM patients " +
                       "ORDER BY surname "
            delegate: patientDelegate
        }   // ListView

    I have followed this example to subclass QSqlQueryModel and use it in QML (don't know if this matters):

    What am I doing wrong? I also tried to set patientList.contentY, but this is very slow.

  • It turns out to be a problem of the model. I rewrote the model from scratch to inherit from QAbstractListModel. Now the positioning works.

    Unfortunately, it seems that I can't mark this as solved.

  • Lifetime Qt Champion


    Thanks for sharing your solution.

    To mark as solved just edit the thread title and prepend [solved] to it :)

Log in to reply