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. View with one model item
Qt 6.11 is out! See what's new in the release blog

View with one model item

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

    Hi,
    is there a way to display one item from model per page? When user clicks next button, next item from model is loaded into to the page.

    I know ListVIew, but it displays all items from model.

    E 1 Reply Last reply
    1
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by A Former User
      #2

      You mean smiliar to this?

      import QtQuick 2.7
      import QtQuick.Controls 2.0
      import QtQuick.Layouts 1.0
      
      ApplicationWindow {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
      
          ListModel {
              id: fruitModel
              ListElement { name: "Apple" }
              ListElement { name: "Orange" }
              ListElement { name: "Banana" }
          }
      
          Row {
              id: myRow
              anchors.centerIn: parent
              spacing: 10
              property int currentItem: 0
              Label {
                  width: 100
                  text: fruitModel.get(myRow.currentItem).name
              }
              Button {
                  text: "Next"
                  onClicked: myRow.currentItem = (myRow.currentItem < fruitModel.count - 1) ? ++myRow.currentItem : 0
              }
          }
      }
      
      1 Reply Last reply
      2
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
        wrote on last edited by
        #3

        You don't need listview. Also there is nothing like u need to use model with view only. As @Wieland suggested you can directly fetch data from model and display it

        Dheerendra
        @Community Service
        Certified Qt Specialist
        https://www.pthinks.com

        C 1 Reply Last reply
        1
        • M MartinD

          Hi,
          is there a way to display one item from model per page? When user clicks next button, next item from model is loaded into to the page.

          I know ListVIew, but it displays all items from model.

          E Offline
          E Offline
          Eeli K
          wrote on last edited by
          #4

          @MartinD StackView may be what you want. Both Controls 1 and 2 have their own StackView.

          1 Reply Last reply
          0
          • dheerendraD dheerendra

            You don't need listview. Also there is nothing like u need to use model with view only. As @Wieland suggested you can directly fetch data from model and display it

            C Offline
            C Offline
            Curtwagner1984
            wrote on last edited by Curtwagner1984
            #5

            @dheerendra Could you elaborate on how one would go about directly fetching data from a C++ model using the user roles that are present in the model ?
            @Eeli-K Wouldn't StackView also load all the items in the model? I mean, every time you push "next" the next item will be pushed onto the stack, so if you push next 30 times you'll have 30 items in the stack, and I think @MartinD wants that 1 item will be loaded at any given time. Also how would one go about accessing the models USER ROLES in a stackview ?

            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