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. How to set the position in QML List view
Forum Updated to NodeBB v4.3 + New Features

How to set the position in QML List view

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 517 Views 1 Watching
  • 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.
  • P Offline
    P Offline
    Praveen.Illa
    wrote on last edited by Praveen.Illa
    #1

    Hi Team,

    I have a QML list view with several list elements.
    I want to display the list view from a specific position i.e. based on contentY value.
    How can I implement this ?

    Please find the sample code and picture below

    ListModel {
            id: contactModel
            ListElement {
                name: "Bill Smith"
                number: "555 3264"
            }
            ListElement {
                name: "John Brown"
                number: "555 8426"
            }
            ListElement {
                name: "Sam Wise"
                number: "555 0473"
            }
            ListElement {
                name: "Shyam"
                number: "555 0473"
            }
            ListElement {
                name: "Birbal"
                number: "555 0473"
            }
            ListElement {
                name: "Rudra"
                number: "555 0473"
            }
            ListElement {
                name: "Samyukta"
                number: "555 0473"
            }
            ListElement {
                name: "Akh"
                number: "555 0473"
            }
            ListElement {
                name: "Chris"
                number: "555 0473"
            }
        }
    
        ListView {
            id: listView
            anchors.fill: parent
            model: contactModel
            delegate: Text {
                font.pixelSize: 14
                text: name + ": " + number
            }
        }
    

    55de7dbd-6c5d-411f-9065-530bd960979e-image.png

    sierdzioS 1 Reply Last reply
    0
    • sierdzioS sierdzio

      @Praveen-Illa said in How to set the position in QML List view:

      I want to display the list view from a specific position i.e. based on contentY value.
      How can I implement this ?

      You have answered yourself here: use contentY property :-) For example:

      ListView {
        // ...
        Component.onCompleted: contentY = 50
      }
      

      There are also other methods to better position the views, see the docs: https://doc.qt.io/qt-5/qml-qtquick-listview.html#positionViewAtIndex-method

      P Offline
      P Offline
      Praveen.Illa
      wrote on last edited by Praveen.Illa
      #3

      @sierdzio Thank You

      ListView {
              id: listView
              anchors.fill: parent
              model: contactModel
              delegate: Text {
                  font.pixelSize: 14
                  text: name + ": " + number
              }
      
              onCountChanged: listView.contentY = 52
          }
      
      1 Reply Last reply
      0
      • P Praveen.Illa

        Hi Team,

        I have a QML list view with several list elements.
        I want to display the list view from a specific position i.e. based on contentY value.
        How can I implement this ?

        Please find the sample code and picture below

        ListModel {
                id: contactModel
                ListElement {
                    name: "Bill Smith"
                    number: "555 3264"
                }
                ListElement {
                    name: "John Brown"
                    number: "555 8426"
                }
                ListElement {
                    name: "Sam Wise"
                    number: "555 0473"
                }
                ListElement {
                    name: "Shyam"
                    number: "555 0473"
                }
                ListElement {
                    name: "Birbal"
                    number: "555 0473"
                }
                ListElement {
                    name: "Rudra"
                    number: "555 0473"
                }
                ListElement {
                    name: "Samyukta"
                    number: "555 0473"
                }
                ListElement {
                    name: "Akh"
                    number: "555 0473"
                }
                ListElement {
                    name: "Chris"
                    number: "555 0473"
                }
            }
        
            ListView {
                id: listView
                anchors.fill: parent
                model: contactModel
                delegate: Text {
                    font.pixelSize: 14
                    text: name + ": " + number
                }
            }
        

        55de7dbd-6c5d-411f-9065-530bd960979e-image.png

        sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #2

        @Praveen-Illa said in How to set the position in QML List view:

        I want to display the list view from a specific position i.e. based on contentY value.
        How can I implement this ?

        You have answered yourself here: use contentY property :-) For example:

        ListView {
          // ...
          Component.onCompleted: contentY = 50
        }
        

        There are also other methods to better position the views, see the docs: https://doc.qt.io/qt-5/qml-qtquick-listview.html#positionViewAtIndex-method

        (Z(:^

        P 1 Reply Last reply
        1
        • sierdzioS sierdzio

          @Praveen-Illa said in How to set the position in QML List view:

          I want to display the list view from a specific position i.e. based on contentY value.
          How can I implement this ?

          You have answered yourself here: use contentY property :-) For example:

          ListView {
            // ...
            Component.onCompleted: contentY = 50
          }
          

          There are also other methods to better position the views, see the docs: https://doc.qt.io/qt-5/qml-qtquick-listview.html#positionViewAtIndex-method

          P Offline
          P Offline
          Praveen.Illa
          wrote on last edited by Praveen.Illa
          #3

          @sierdzio Thank You

          ListView {
                  id: listView
                  anchors.fill: parent
                  model: contactModel
                  delegate: Text {
                      font.pixelSize: 14
                      text: name + ": " + number
                  }
          
                  onCountChanged: listView.contentY = 52
              }
          
          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