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. [SOLVED] A listmodel Index problem, thanks for your help!
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] A listmodel Index problem, thanks for your help!

Scheduled Pinned Locked Moved QML and Qt Quick
11 Posts 5 Posters 4.9k Views 1 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.
  • O Offline
    O Offline
    open-src
    wrote on last edited by
    #1

    Hi, I am a newbie. I has a listmodel, two corresponding views. Someone can tell me how to obtain an ListView currentIndex ,and then pass it to another Pathview as its current Index.

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      Have a look at selection model.
      Basically you set the selectionmodel of qlistview2 to selectionmodel of qlistview1. But it works in both directions!

      Edit:
      Btw what is a pathview? Another listview?

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • L Offline
        L Offline
        loladiro
        wrote on last edited by
        #3

        Something like
        @ui->pathView->setCurrentIndex(ui->listView->currentIndex())@ ?

        EDIT: Sorry, I missed that it was QML

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DenisKormalev
          wrote on last edited by
          #4

          OP uses QML views, not widget ones :)

          About problem. Add to your listview
          @
          onCurrentIndexChanged: pathView.currentIndex = currentIndex
          @

          1 Reply Last reply
          0
          • T Offline
            T Offline
            thisisbhaskar
            wrote on last edited by
            #5

            And one more thing you may want to know is that deligate has to set currentIndex of the list view.

            in MouseArea of deligate component have something like this..

            listViewItem.currentIndex = index // sets the currentIndex of listViewItem to current items index

            1 Reply Last reply
            0
            • O Offline
              O Offline
              open-src
              wrote on last edited by
              #6

              Thanks for your reply!

              @Vijay Bhaska Reddy
              I am programming a picture viewer, using a ListModel Item, two Views(one is a ListView Item, the other is a PathView Item).I want to click a picture in a ListView Item,then switch to display the picture in the PathView Item.
              I have a try according to your advice, but I find a new problem:When switching to the PathView Item, the program always slides in the PathView Item from the first picture to the picture which is clicked in the ListView Item. Can you give me some help again?

              1 Reply Last reply
              0
              • T Offline
                T Offline
                thisisbhaskar
                wrote on last edited by
                #7

                wow.. this is interesting. That should not happen as we are not updating currentIndex of PathView. Are you updating currentIndex of PathView when we update currentIndex of ListView?

                So, basically what you want is when you switch from ListView to PathView, PathView should be showing the first item?

                1 Reply Last reply
                0
                • O Offline
                  O Offline
                  open-src
                  wrote on last edited by
                  #8

                  @Vijay Bhaska Reddy
                  I do not want PathView to show the first item, I want it to show the item which is cliked in the ListView.
                  I find that setting the PathView currentIndex value , But PathView don't display the corresponding item. I guess this issue should be related to its model. shouId I use proxy model?

                  BTW:I think , I don't understand the ability of the currentIndex, so misuse it.

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    thisisbhaskar
                    wrote on last edited by
                    #9

                    ok I guess I know why this might be happening. once you set currentIndex on PathView, add the below code also

                    @ pathView.positionViewAtIndex(pathView.currentIndex, ListView.Center)@

                    this basically scrolls PathView such that item index provided in first parameter shown at the center of the PathView item. Hope this solves our problem.

                    And about your currentIndex understanding, this property basically tells which is the currently selected item in the PathView and property 'highlight' component is used to hightlight currentIndex item. This is generally needed in ListView and may not be in your case.

                    what you are doing with that code I have suggested is, making the item you clicked in ListView as currentItem in PathView and asking PathView to display currentItem at the center of the PathView item.

                    1 Reply Last reply
                    0
                    • O Offline
                      O Offline
                      open-src
                      wrote on last edited by
                      #10

                      @Vijay Bhaska Reddy

                      Aha, it works!
                      I'm really grateful to you for your patience!

                      1 Reply Last reply
                      0
                      • T Offline
                        T Offline
                        thisisbhaskar
                        wrote on last edited by
                        #11

                        you are welcome :).

                        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