I'm trying to figure out how to create a reusable EditorDelegate for the QML TreeView Component.
I was able to create an workable Editor Delegate for one column with the role end. But my TreeView has 3 columns, namely name, start and end.
I tried to simply set styleData.value=textEdit.text instead of modelEnd=textEdit.text, but seemingly styleData.value is an read-only property.
How can I make my EditorDelegate be reusable for all columns alike?
EditorDelegate.qml import QtQuick 2.0
Rectangle {
anchors.fill: parent
Text {
anchors.fill: parent
id: textDisplay
visible: true
text: styleData.value
}
TextInput {
anchors.fill: parent
id: textEdit
text: styleData.value
visible: false
onVisibleChanged: {
focus: parent
}
onAccepted: {
model.end=textEdit.text; // Can be model.name, model.start, model.<role>???
textEdit.visible=false
textDisplay.visible=true
}
onFocusChanged: {
if (!focus) {
textEdit.visible=false
styleData.value=textEdit.text
textDisplay.visible=true
}
}
}
MouseArea {
id: mouseArea
acceptedButtons: Qt.AllButtons
anchors.fill: parent
onDoubleClicked: {
if (mouse.button & Qt.LeftButton) {
textDisplay.visible=false
textEdit.visible=true
textEdit.forceActiveFocus()
}
}
}
}
The usage should be something like this:
import QtQuick 2.9
import QtQuick.Window 2.3
import QtQuick.Controls 1.4
Window {
visible: true
TreeView {
id: treeView
anchors.fill: parent
TableViewColumn {
title: "Value"
role: "name"
delegate: EditorDelegate { }
}
TableViewColumn {
title: "Start"
id: start
role: "start"
delegate: EditorDelegate { }
}
TableViewColumn {
title: "End"
id: end
role: "end"
delegate: EditorDelegate { }
}
model: itemModel
}
}
Here I have another problem, as EditorDelegate has no means of opening and collapsing tree nodes. But this is a completely different story.