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. ListView: Scrollbar should scroll by whole items
Forum Updated to NodeBB v4.3 + New Features

ListView: Scrollbar should scroll by whole items

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 478 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.
  • M Offline
    M Offline
    maxwell31
    wrote on last edited by
    #1

    I have a ListView with a scroll bar. I would like the scrollbar to scroll by whole items, so that I don't have a partial item at the top. How can this be done?

    1 Reply Last reply
    0
    • YunusY Offline
      YunusY Offline
      Yunus
      wrote on last edited by
      #2

      @maxwell31 hi. What I understood is that you have a list like in this example( https://doc.qt.io/qt-5/qtlocation-places-list-example.html)
      and you dont want its elements to disappear when you scroll. or am I wrong? You may explain with an image more specifically.

      1 Reply Last reply
      0
      • Shrinidhi UpadhyayaS Offline
        Shrinidhi UpadhyayaS Offline
        Shrinidhi Upadhyaya
        wrote on last edited by
        #3

        Hi @maxwell31 , you can use a property called snapMode.

        Here is the sample code:-

          ListView {
            width: 180; height: 200
        
            model: 10
            spacing: 10
            snapMode: ListView.SnapToItem
            delegate: Rectangle {
                height: 100
                width: 100
                color: "red"
        
                Text {
                    anchors.centerIn: parent
                    text: index
                }
            }
        }
        

        Shrinidhi Upadhyaya.
        Upvote the answer(s) that helped you to solve the issue.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maxwell31
          wrote on last edited by
          #4

          My ListView is like this:

                  ListView {
                      width:1400
                      height:345
                      anchors.left: parent.left
                      anchors.leftMargin: 20
                      anchors.top: parent.top
                      anchors.topMargin: 600
                      spacing: -1
                      model: mylist
                      boundsBehavior: Flickable.StopAtBounds
                      clip: true
                      ScrollBar.vertical: ScrollBar {
                          minimumSize: 0.15
                          snapMode: ScrollBar.SnapAlways
                          policy: ScrollBar.AlwaysOn
                      }
                      snapMode: ListView.SnapToItem
                      delegate: MyDelegate{}
                  }
          

          The snapmode works fine, if I scroll by dragging the view, but if I move the scrollbar at the right edge, I can also scroll in a way, that I only see part of an item.

          1 Reply Last reply
          0
          • Shrinidhi UpadhyayaS Offline
            Shrinidhi UpadhyayaS Offline
            Shrinidhi Upadhyaya
            wrote on last edited by
            #5

            Hi @maxwell31 , you need to set the stepSize of the scrollbar also.

            Here is the sample code please have a look:-

             ListView {
                width: 180; height: 200
            
                model: 10
                spacing: 10
                snapMode: ListView.SnapToItem
            
                ScrollBar.vertical: ScrollBar {
                    minimumSize: 0.15
                    stepSize: 0.125
                    snapMode: ScrollBar.SnapOnRelease
                    //####Here are other options also,try the one which suits you
                    //1. ScrollBar.SnapAlways
                    //2. ListView.SnapToItem
                    policy: ScrollBar.AlwaysOn
                }
            
                delegate: Rectangle {
                    height: 100
                    width: 100
                    color: "red"
            
                    Text {
                        anchors.centerIn: parent
                        text: index
                    }
                }
            }
            

            Shrinidhi Upadhyaya.
            Upvote the answer(s) that helped you to solve the issue.

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved