user123445151156
user123445151156

Reputation: 361

How to display model in QML with pages?

I have problem with displaying model with pages, and I can't find what is proper way to do this.

I have ListView which has model of 15 rectangles like in the picture below.enter image description here

There is property currentPage which is changed when clicking the buttons. I want to be able to display:

0-4 elements in the first page
5-9 in the second
And last 5 on the third page.

I know that I can create them for example FirstPage.qml, SecondPage.qml... And use them directly, but I want to display Items from model. The ListView is not important it can be any component but I want to use model.

What is the best way to achieve this? Any idea suggestion is welcome.

Upvotes: 0

Views: 504

Answers (1)

JarMan
JarMan

Reputation: 8277

ListView has a method called positionViewAtIndex() that will allow you to specify which item to scroll to. So for your case, you could do something like this:

Button {
    id: previousBtn
    onClicked: {
        listView.positionViewAtIndex(listView.currentIndex - 5);
    }
}
Button {
    id: nextBtn
    onClicked: {
        listView.positionViewAtIndex(listView.currentIndex + 5);
    }
}

Upvotes: 2

Related Questions