开发者

How to get selected listitem index in Qt

I am having a QListView which contains some items. Now I want to get the index of selected item开发者_StackOverflow中文版, i.e. if I select 5th element I should get 5. How I can get this?


In every view in Qt, you have the following method :

QItemSelectionModel * QAbstractItemView::selectionModel () const

Basically, it returns a model on which you can perform actions, like getting selected indexes...

Have a look here : QItemSelectionModel

You'll find plenty of methods to help you get your index(es).

Hope it helps!


There is no easy way to do this, since QListView can handle tree like structures. You can make your list items derive from QListViewItem and add an extra data member to hold an index. You have to reset the indexes when sorting of course.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜