How to get the Index from a ListView



  • I'm trying to get the index from a listview when I dragging the item to over.
    I'm using listview.currentIndex but I always get 0 as an index.
    I have also tried using the delegateId.ListVeiw.currentIndex , I get a reference error ReferenceError.

    I need the index so that I may remove the Item from the return index.

    Any help is appreciated.



  • @Arnie77
    I am only guessing, but if you mean you are dragging something else over the listview and want to know which item the drag is over(?), won't you need to use QModelIndex QListView::indexAt(const QPoint &p) const ?



  • @JonB said in How to get the Index from a ListView:

    QListView
    Thanks for the reply, JonB.

    Here is an Image that would help you understand what I'm trying to accomplish.
    0_1515105017443_6d713752-b746-4122-a9ec-aa551b977eab-image.png

    ListView in on the right and I'm dragging it over to the Item on the left.
    When dragging the from the ListView to the Play Item, I want to know the Index of the ListView Item I'm dragging over to the other the Play Item.



  • @Arnie77

    ListView in on the right and I'm dragging it over to the Item on the left.

    ?? ListView on left and dragging item over to widget at right ??

    This appears to be the opposite way round from what I first understood you to be saying. You seem to be dragging an item out of the listview to somewhere else, not dragging something else over on top of a listview item.



  • @JonB

    Yes, that is what I meant.



  • in the play area you'll have a drop event that contains the QMimeData with the information you need



  • I was able to figure out how to access the index.
    I was trying to access it via listview.currentIndex, but that only seems to work when using the keyboard arrow keys to move between items. If you are using the mouse then index from the ListModel it what you want use.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.