diff options
Diffstat (limited to 'src/quickcontrols/material/TreeViewDelegate.qml')
-rw-r--r-- | src/quickcontrols/material/TreeViewDelegate.qml | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/quickcontrols/material/TreeViewDelegate.qml b/src/quickcontrols/material/TreeViewDelegate.qml index a7be36a555..1a6e35dadc 100644 --- a/src/quickcontrols/material/TreeViewDelegate.qml +++ b/src/quickcontrols/material/TreeViewDelegate.qml @@ -58,5 +58,40 @@ T.TreeViewDelegate { contentItem: Label { text: control.model.display elide: Text.ElideRight + visible: !control.editing } + + // The edit delegate is a separate component, and doesn't need + // to follow the same strict rules that are applied to a control. + // qmllint disable attached-property-reuse + // qmllint disable controls-sanity + TableView.editDelegate: FocusScope { + width: parent.width + height: parent.height + + readonly property int __role: { + let model = control.treeView.model + let index = control.treeView.modelIndex(column, row) + let editText = model.data(index, Qt.EditRole) + return editText !== undefined ? Qt.EditRole : Qt.DisplayRole + } + + TextField { + id: textField + x: control.contentItem.x + y: (parent.height - height) / 2 + width: control.contentItem.width + text: control.treeView.model.data(control.treeView.modelIndex(column, row), __role) + focus: true + } + + TableView.onCommit: { + let index = TableView.view.modelIndex(column, row) + TableView.view.model.setData(index, textField.text, __role) + } + + Component.onCompleted: textField.selectAll() + } + // qmllint enable attached-property-reuse + // qmllint enable controls-sanity } |