Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to change content of a QML combobox when the index of another comboBox changes?

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"]
        }
    }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading