Different delegates in TableViewColumn depending on data
-
In QTableView with custom delegate in createEditor I can provide any widget I want to display my data. I have access to model, so I test what data are inside and display them with different widget.
How to achieve the same in TableView/TableViewColumn?
TableViewColumn{ title: "Value" role: "propertyValue" movable: false delegate: { type = propertiesTableView.model.data(propertiesTableView.model.index(styleData.row, styleData.column), 0x0100); //styleData is not defined console.log("Type value for row '"+styleData.row+"' is "+type) if (type == 1) return NodePropertyDelegate.floatDelegate else if (type == 2) return 0
I tried this - but styleData is not present, so I don't know how to get type from model.
-
deletegate should be Component. In your code you are writing code directly.
delegate : Rectangle { width:100;height:100;color:"blue"; Text { text : styleData.value } }
Any processing inside the delegate can be done with appropriate signal handler inside the signal handler of component.
-
Please take a look into sensor_explorer example (Qt 5.11+).
There's part of codeitemDelegate: { if (selectedItem && selectedItem.isWriteable) return editableDelegate; return readOnlyDelegate; }
where code makes selection what to display as delegate depending on few properties of TableView.
I'm referring to this kind of code to select which delegate to show. -
You could use
DelegateChooser
-
Cool, that's what I was looking for.