ComboBox textRole doesn't work on custom delegate
Solved
QML and Qt Quick
-
Hi guys, I create a custom ComboBox component, when I use a simple model with a single role the component works with no problems, but if I use it with QAbstractListModel and set the roleText property I get this error:
Unable to assign [undefined] to QString
This is how I set the ComboBox:
IndigoComboBox{ model: mymodel textRole: "customUserRole" }
This is the Text component inside the delegate:
Text{ text: modelData //I also try with textRole }
Does anyone have an idea of what could be happening?
-
It's the delegate that does the logic of fetching the data based on the textRole.
change your delegate's text to :
text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData
where control is an id to your ComboBox
-
Thanks! that works perfectly