Unsolved Delegating item for combobox (QML)
-
Hi, My requirement is like, i have following model data for combobox
suppose > model: ["102", "304", "509"]
i need to display these model data in combobox as below.Combodata
Code-1
Code-2
Code-3and if i selected Code-2 i should get 304 as value (actual model data.). How
can i do this in QML combobox. ? Is there any way to achieve this in cobobox
as we can do in tableview with delegate. ? Could you please help me to sove
thi.? -
You try to do this:
ComboBox { id: cmb property string currentValue: "" currentIndex: 0 model: ListModel { id: cbItems ListElement { text: "Code-1"; value: "102" } ListElement { text: "Code-2"; value: "304" } ListElement { text: "Code-3"; value: "509" } } width: 200 onCurrentIndexChanged: { cmb.currentValue = cbItems.get(currentIndex).value; } }
Hope this helps!
-
Got some easy fix by creating Wrapper for model.
code below*****
// creating wrapper for the model
Repeater {
model: tableModels.Study.GetStudyIDList(tableModels.Patient.get(modelIndx, "ID")) // My actual model exposed from C++ side
delegate: Item {
Component.onCompleted: {
wrapper.append({text: "Code " + getStudyID(index), value: modelData })
}
}
}
ComboBox {
id: studyList
height: 30
model: ListModel { id: wrapper }
}function getStudyID( index ) { // just append 0 befor number from 0 -9 var studyNum = index + 1; if(index<10 && index>-1) { studyNum = "0" + studyNum; } return studyNum; }
Anyway thank you literA2 ..!