I have a working QListView, but from the documentation, I can't figure out how to get a signal to fire with the index of the newly selected item. Any ideas?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Imho, an easier way to achieve this would be to use a QListWidget instead of a QListView, this way you could use the itemClicked signal, which sends the selected item to the callback function.
回答2:
These is a snipplet of code of how I achieved it:
class VenueList(QListView):
def __init__(self, parent, venues):
super(VenueList, self).__init__(parent)
self.clicked.connect(self.venue_selected)
[...]
def venue_selected(self, index):
venue = self.model().data(index, VenueListModel.VenueRole)
doStuff()
You can browse the full code of how I used this here (line 69). I do warn you, however, that this code is pretty bad, and needs some serious refactoring.