Reputation: 153
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?
Upvotes: 1
Views: 4302
Reputation: 9906
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.
Upvotes: 0
Reputation: 18019
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.
Upvotes: 1