How control to move next page in ListView



  • 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)
                }
            }
        }
    }
    

  • Moderators

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



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.