I use
QObject.connect(self.image_list, QtCore.SIGNAL('clicked(QModelIndex)'), self.on_row_changed)
initially, but I find that when I press the right button, on_row_changed
will be called even though the item is grey(not the focus). Which signal should I connect?
I search through the documentation for qt4.8, and the signals activated (const QModelIndex &index )
, void indexesMoved (const QModelIndexList &indexes)
do not work.
So, when I try to do some action based on the focus item, which signal should I use that when I move the single-selection item using mouse or up/down arrow, a call-back will be invoked correctly?
For a QListView
, you should connect to one of the signals of its selection model. To get changes to the current item as well as the selection, do:
self.image_list.selectionModel().currentChanged.connect(self.on_row_changed)
...
def on_row_changed(self, current, previous):
print('Row %d selected' % current.row())