Search code examples
mappingqcomboboxqlineedit

how to select combobox item based on values on other widget in pyqt


I have a lineEdit and a combobox.

I have data as below

---------------------
|ID    | DisplayName|
---------------------
|100   | OneHundred |
|150   | OneFifty   |
|25    | TwendyFive |
---------------------

I added DisplayNames as items in combobox.

I want to do as below

when i enter 100 in lineedit, then "OneHundred" item to be selected in combobox when i enter 25 in lineedit, then "TwentyFive" item to be selected in combobox

it should work like this.

Can any one suggest a method to achieve this....


Solution

  • I found a solution what i asked for.

    I used userData to achieve this. Added items to combobox as below

    ID = ['100','150','25']
    Name = ['OneHundred','OneFifty','TwentyFive']
    
    for i in xrange(3):
    
        cmbobox.addItem(Name[i],ID[i])
    

    For lineedit textchange i wrote as below

    index = comobox.findData(lineedit.text())
    combobox.setCurrentIndex(index)