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 control to move next page in ListView
Forum Updated to NodeBB v4.3 + New Features

How control to move next page in ListView

Scheduled Pinned Locked Moved QML and Qt Quick
qmllistview
3 Posts 2 Posters 1.1k Views 2 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.
  • J Offline
    J Offline
    Jean
    wrote on last edited by Jean
    #1

    Hello.

    I want to move page units in ListView.

    There's very simple example.
    ListView has 10 items and display 4 items per 1 page at same time.

    1page - 0,1,2,3
    2page - 4,5,6,7
    3page - 8,9

    I move next page using positionViewAtindex().
    It seems to work correctly, but It works incorrectly when I move last page.
    ListView shows 6,7,8,9 items including previous page's item(6,7).

    Please give me some advice.

    import QtQuick 2.0
    
    Item {
    	id: root
        width: 1280; height: 720
    
        ListView {
            id: list
            width: 100; height: 100*4
            focus: true
            clip: true
            model: 10
            delegate: Rectangle {
                width: 100; height: 100
                color: index==list.currentIndex ? "red" : "black"
                Text {
                    text: index
                    color: "white"
                    anchors.centerIn: parent
                }
            }
            Keys.onDownPressed: {
                if(list.currentIndex<(list.count-1))
                {
                    list.currentIndex++;
                    if(list.currentIndex%4==0)
                       list.positionViewAtIndex(list.currentIndex, ListView.Beginning)
                }
            }
        }
    }
    
    p3c0P 1 Reply Last reply
    0
    • J Jean

      Hello.

      I want to move page units in ListView.

      There's very simple example.
      ListView has 10 items and display 4 items per 1 page at same time.

      1page - 0,1,2,3
      2page - 4,5,6,7
      3page - 8,9

      I move next page using positionViewAtindex().
      It seems to work correctly, but It works incorrectly when I move last page.
      ListView shows 6,7,8,9 items including previous page's item(6,7).

      Please give me some advice.

      import QtQuick 2.0
      
      Item {
      	id: root
          width: 1280; height: 720
      
          ListView {
              id: list
              width: 100; height: 100*4
              focus: true
              clip: true
              model: 10
              delegate: Rectangle {
                  width: 100; height: 100
                  color: index==list.currentIndex ? "red" : "black"
                  Text {
                      text: index
                      color: "white"
                      anchors.centerIn: parent
                  }
              }
              Keys.onDownPressed: {
                  if(list.currentIndex<(list.count-1))
                  {
                      list.currentIndex++;
                      if(list.currentIndex%4==0)
                         list.positionViewAtIndex(list.currentIndex, ListView.Beginning)
                  }
              }
          }
      }
      
      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi @Jean,
      IMO, StackView would be more suitable in your scenario.

      157

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jean
        wrote on last edited by
        #3

        Hi @p3c0 ,

        StackView looks good but unfortunately I couldn't use it in QT 4.8.6.
        I think I need to analysis the operation of ListView in QT open source.
        Thanks for your response.

        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