Clicking the tableView's item
opens a PersistentEditor
: it defaults to QSpinBox
for the first column (since integer data) and QLineEdit
for two others.
onClick
I would like to query how many persistent editors have been already opened for the clicked row.
from PyQt4 import QtCore, QtGui
app = QtGui.QApplication([])
class Model(QtCore.QAbstractTableModel):
def __init__(self):
QtCore.QAbstractTableModel.__init__(self)
self.items = [[1, 'one', 'ONE'], [2, 'two', 'TWO'], [3, 'three', 'THREE']]
def flags(self, index):
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsEditable
def rowCount(self, parent=QtCore.QModelIndex()):
return 3
def columnCount(self, parent=QtCore.QModelIndex()):
return 3
def data(self, index, role):
if not index.isValid(): return
if role in [QtCore.Qt.DisplayRole, QtCore.Qt.EditRole]:
return self.items[index.row()][index.column()]
def onClick(index):
tableView.openPersistentEditor(tableView.model().index(index.row(), index.column()))
print 'clicked index: %s'%index
tableModel=Model()
tableView=QtGui.QTableView()
tableView.setModel(tableModel)
tableView.clicked.connect(onClick)
tableView.show()
app.exec_()