简体   繁体   English

PyQt4中QListView的clicked()信号

[英]clicked() signal for QListView in PyQt4

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. 我有一个工作正常的QListView,但是从文档中,我无法弄清楚如何使用新选择的项目的索引来触发信号。 Any ideas? 有任何想法吗?

恕我直言,更简单的方法是使用QListWidget而不是QListView,这样您可以使用itemClicked信号,该信号将选定的项目发送到回调函数。

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). 您可以在此处浏览有关如何使用此代码的完整代码(第69行)。 I do warn you, however, that this code is pretty bad, and needs some serious refactoring. 但是,我确实警告您,此代码非常糟糕,需要进行认真的重构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM