Unsolved Editable TableViewColumn and Delegate
-
Hi,
I am new to QML and trying to use TableViewColumn and Delegate
I am using TextEdit inside delgate but when I edit the text the changes are not being reflected to the backend
I tried using onTextChanged, onEditingChanged but nothing works
Please helpFocusScope { property alias model: tableView1.model Rectangle { anchors.fill: parent color: "#2e2e2e" TreeView { id: tableView1 anchors.fill: parent anchors.margins: 20 TableViewColumn { role: "name" title: qsTr("Name") width: 150 } TableViewColumn { role: "default" title: qsTr("Default Value") width: 150 delegate: TextEdit { text: styleData.value } } TableViewColumn { role: "map" title: qsTr("Value Map") width: 300 delegate: Row { spacing: 10 Repeater { model: styleData.value delegate: Row { TextEdit { text: name + "=" } TextEdit { text: value font.bold: variable } } } } } } } }
-
Have a look at this: https://forum.qt.io/topic/89143/help-with-qml-tableview
-
@maxwell31 I'm biased but the solution of modifying the model doesn't sound very clean to me when you can do it without modification to the model.
-
Not sure I understand what you mean. I think the model should be modified. Maybe have a look at http://doc.qt.io/qt-5/model-view-programming.html
-
@maxwell31 Sorry my remark wasn't very clear :)
Modified as in add an
updateValue
method when the delegate can already callsetData
itself automatically when doingmodel.yourRole = newValue
-
True. You should be able to use setData, but the problem might be to get the right role number. The prototype is
setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole)
and I don't know how to use the role name for the integer. Please tell me when you solved that
-
@maxwell31
Doingmodel.roleName = newValue
in the QML delegate is the same as doingmyModel.setData(myModel.index(row, 0), newValue, roleNumber)
except that you don't have to figure out the role number. -
@GrecKo
Ah, good to know -
Hi,
I tried the above it works. Thank you !
I am able to edit existing values.
Is there a way to add values in new row? -
@MTOLANI That's specific to the model you are using.