[Interest] Setting currentIndex in Qt Quick ComboBox does not work

Fabian Sturm f at rtfs.org
Wed Mar 23 22:24:02 CET 2016


Hi Jerome!

Thanks a lot for your help and I already read the article and tried for
another several hours. Unfortunately I still can only get one half
working. Here is the new code for the event propagation:

ComboBox {
    id: combo
    width: parent.width
    model: mymodel.items // order is important
    currentIndex: getCurrentIndex(mymodel.items, mymodel.item)
    onCurrentIndexChanged: mymodel.item = model[currentIndex]
    textRole: 'name'
    Component.onCompleted: {
        combo.modelChanged.connect(modelUpdated)
    }
    function modelUpdated() {
        console.log('model updated')
        // tried to set the index here but the vaue is already
overriden
    }
}

With this the model is loaded first and then the index is set to the
correct initial value. But with this solution I can only append to the
model once and after the append, the index will be wrong.

I also don't seem to be able to save the currentIndex at the right
time. Therefore a small working example would really be great!

My updated code is again at: 
https://github.com/sturmf/python_samples/tree/master/pyqt_combobox

Thanks a lot,
Fabian

Am Mittwoch, den 23.03.2016, 10:11 -0400 schrieb Jérôme Godbout:
> Hi,
> You have a binding problem here inside the combobox: 
> currentIndex: getCurrentIndex(mymodel.items, mymodel.item)

> > 
> > The sample source is here:
> > https://github.com/sturmf/python_samples/tree/master/pyqt_combobox
> > 




More information about the Interest mailing list