[SOLVED] A listmodel Index problem, thanks for your help!
-
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.
-
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? -
Something like
@ui->pathView->setCurrentIndex(ui->listView->currentIndex())@ ?EDIT: Sorry, I missed that it was QML
-
OP uses QML views, not widget ones :)
About problem. Add to your listview
@
onCurrentIndexChanged: pathView.currentIndex = currentIndex
@ -
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
-
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? -
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?
-
@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.
-
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.
-
@Vijay Bhaska Reddy
Aha, it works!
I'm really grateful to you for your patience! -
you are welcome :).