Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Problems setting ComboBox currentIndex



  • QuickControls 2 using Qt 5.11....

    I've got a comboBox, and I'm trying to change the model and current index for it using javascript on a property change:

    onMyPropertyChanged: {
                        
            if (MyProperty <100){
                 model= ["15"];
                  myComboBox.currentIndex = 0;
            }
           else {
                model=["15","27"];
                myComboBox.currentIndex = 1;
           }
    }
    

    I'm seeing the correct choices in the menu after the property change happens, but the menu looks blank, as if index -1 has been chosen. If I print the currentText for the comboBox, it reports the correct choice is selected, but it's not showing.

    Is there some sort of refresh that needs to happen in order to see the correct index showing?



  • @igor_stravinsky hi,

    you don't need to refresh, i just tested this and it works a expected

    Window {
        visible: true
        width: 640
        height: 480
        property bool tgl:false
    
        onTglChanged: {
            combo.model = ["1111","2222","3333"]
            combo.currentIndex=2;
        }
    
        ComboBox {
            id:combo
            editable: true
            model:["11","22","33"]
        }
    
        Button{
            anchors.centerIn: parent
            onClicked: tgl = !tgl
            text:"combo index : " + combo.currentIndex
        }
    }
    

Log in to reply