Firstly, we don't overwrite the method 'setModelData'
Code: Select all
from PySide import QtCore, QtGui
import FreeCADGui
ui = FreeCADGui.UiLoader()
class MaterialDelegate(QtGui.QStyledItemDelegate):
def createEditor(self, parent, option, index):
if index.column() == 1:
# editor = QtGui.QLineEdit()
editor = ui.createWidget("Gui::InputField")
editor.setParent(parent)
return editor
def setEditorData(self, editor, index):
print('setEditorData')
data = index.data()
editor.setText(data)
'''def setModelData(self, editor, model, index):
data = editor.text()
model.setData(index, data)'''
def showData(self, model):
print('showData')
item = model.item(0, 1)
print(item.text())
model = QtGui.QStandardItemModel()
tableView = QtGui.QTableView()
tableView.setModel(model)
delegate = MaterialDelegate()
tableView.setItemDelegate(delegate)
item = QtGui.QStandardItem("MyProperty")
it = QtGui.QStandardItem()
it.setText("10 m")
model.appendRow([item, it])
tableView.setWindowTitle("MaterialDelegate")
tableView.show()
Later on, the model's source of data could be updated with a new function
showData
11,00 m
This could be manually (Apply or Save button) or automatically capturing the editor signal.
EDIT: this avoids the problem we're having with Gui::InputField and the class Delegate