Basically If I have a comboBox that has two values. If I choose the first, the second comboBox content changes into ["60"]. If it's the second index, then the second comboBox's values changes back to ["20","30","60"] which is the originally initialised content of the comboBox.
ComboBox
{
id: keyTypeComboBox
anchors.centerIn: parent
height: parent.height*0.8
width: parent.width*0.9
model: ["choice 1", "choice 2"]
onCurrentIndexChanged: changeContent();
}
function changeContent()
{
if(ComboBox1.currentIndex == 0){
ComboBox 2 change to ---->["60"]
}else{
ComboBox 2 change to ----> ["20","30","60"]
}
}
CodePudding user response:
You can simply do this by binding currentIndex
property from the first one combobox with the model
property in the second one combobox:
ComboBox {
id: combo1
model: ["choice 1", "choice 2"]
}
ComboBox {
id: combo2
model: combo1.currentIndex === 0 ? ["60"] : ["20","30","60"]
}
Function's usage is not necessary here.
CodePudding user response:
Never mind, I realized what I was doing wrong.
it was the syntax. It should be:
if(ComboBox1.currentIndex == 0){
ComboBox2.model = ["insert data"]
}else{
ComboBox2.model = ["insert other data"]
}