[PyQt] Re: Crash in TableView cell edit

Alberto Berti alberto at metapensiero.it
Tue May 26 11:01:15 BST 2009


You have to keep your editor factory alive outside the scope of the
createTv() method

from PyQt4 import QtCore, QtGui

class EditorFactory(QtGui.QItemEditorFactory):
    pass

def createTv():
  tv = QtGui.QTableView()
  model = QtGui.QStandardItemModel(4, 2, tv)
  tv.setModel(model)

  delegate = QtGui.QStyledItemDelegate(tv)
  edfactory = EditorFactory()
  delegate.setItemEditorFactory(edfactory)
  tv.setItemDelegate(delegate)

  for row in range(4):
    for column in range(2):
      index = model.index(row, column, QtCore.QModelIndex())
      model.setData(index, QtCore.QVariant((row+1) * (column+1)))
  return edfactory, tv

if __name__ == '__main__':
  import sys
  app = QtGui.QApplication(sys.argv)
  edfactory, tableView = createTv()
  tableView.show()
  sys.exit(app.exec_())



More information about the PyQt mailing list