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. ListModel and item
Forum Updated to NodeBB v4.3 + New Features

ListModel and item

Scheduled Pinned Locked Moved QML and Qt Quick
6 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.
  • mrdebugM Offline
    mrdebugM Offline
    mrdebug
    wrote on last edited by
    #1

    My situation is a ListModel and some objects in it:

            ScrollView {
                id: scrollView1
                ListView {
                    id: listView;
                    model: listViewModel;
                    delegate: listViewDelegate;
                }
            }
    
            Component {
                id: listViewDelegate;
                QQShareObject {
                }
            }
    
            ListModel {
                id: listViewModel;
            }
    

    How can I call a function into QQShareObject objects?
    I tried
    listViewModel.get(0).internalFunction()
    but does not work..
    I need to have the current value of my QQShareObject object.

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by p3c0
      #2

      Hi,
      @mrdebug

      Try this

      listView.currentIndex = 6 // or whatever
      console.log(listView.currentItem) // gives the item at 6th position
      

      You can then access its properties. For eg:

      listView.currentItem.myId
      

      157

      1 Reply Last reply
      0
      • mrdebugM Offline
        mrdebugM Offline
        mrdebug
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • mrdebugM Offline
          mrdebugM Offline
          mrdebug
          wrote on last edited by
          #4

          for (var count= 0; count< listView.count; count++) {
          listView.currentIndex= count
          console.log(listView.currentItem.getValue())
          }

          is not a good solution. The line
          listView.currentIndex= count
          changes the current selected item.
          Is possible to have the value of each items without to change the item index?

          p3c0P 1 Reply Last reply
          0
          • mrdebugM mrdebug

            for (var count= 0; count< listView.count; count++) {
            listView.currentIndex= count
            console.log(listView.currentItem.getValue())
            }

            is not a good solution. The line
            listView.currentIndex= count
            changes the current selected item.
            Is possible to have the value of each items without to change the item index?

            p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by
            #5

            @mrdebug then the other way to access delegate would be to use children
            For eg:

            view.contentItem.children[2].myId 
            

            view = id of ListView and myId is declared as Q_PROPERTY in QQShareObject

            157

            1 Reply Last reply
            0
            • mrdebugM Offline
              mrdebugM Offline
              mrdebug
              wrote on last edited by
              #6

              Perfect!

              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