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. [solved] ListView.positionViewAtIndex() is not working
QtWS25 Last Chance

[solved] ListView.positionViewAtIndex() is not working

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.6k 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.
  • M Offline
    M Offline
    m_andrej
    wrote on last edited by m_andrej
    #1

    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): https://wiki.qt.io/How_to_Use_a_QSqlQueryModel_in_QML

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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      m_andrej
      wrote on last edited by m_andrej
      #2

      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.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Thanks for sharing your solution.

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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        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