Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    [solved] ListView.positionViewAtIndex() is not working

    QML and Qt Quick
    2
    3
    1276
    Loading More Posts
    • 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
      m_andrej last edited by m_andrej

      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 Reply Quote 0
      • M
        m_andrej last edited by m_andrej

        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 Reply Quote 0
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          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 Reply Quote 0
          • First post
            Last post