我用
QObject.connect(self.image_list, QtCore.SIGNAL('clicked(QModelIndex)'), self.on_row_changed)
一开始是,但是我发现当我按右键时, on_row_changed
即使该项目是灰色的(不是焦点)也会被调用。我应该连接哪个信号?
我搜索了 qt4.8 的文档,以及信号 activated (const QModelIndex &index )
, void indexesMoved (const QModelIndexList &indexes)
不工作。
那么,当我尝试根据焦点项执行某些操作时,我应该使用哪个信号,以便当我使用鼠标或向上/向下箭头移动单选项时,回调将被正确调用?
最佳答案
对于 QListView
,您应该连接到 signals 之一其selection model 。要获取对当前项目以及选择的更改,请执行以下操作:
self.image_list.selectionModel().currentChanged.connect(self.on_row_changed)
...
def on_row_changed(self, current, previous):
print('Row %d selected' % current.row())
关于python - 在QListView中选择一个项目的信号是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22963306/