0

I have a problem with this piece of code.

projList is a variable of type list. self.projPicker is an instance of QComboBox.

    self.projPicker.addItems(projList)
    self.projPicker.currentTextChanged.connect(self.itemListChange)

def itemListChange(self,value):
    self.projPathLbl.setText("Project :   " + value)

def itemListUpdate(self):
    comboItems = []
    for item in range (self.projPicker.count()):
        comboItems.append(self.projPicker.itemText(item))
    print(comboItems)

With this code, when I add text in in the combobox the self.projPathLbl is updated with the itemListChange() function each time I type a character . My problem is, it doesn't work the same way with the itemListUpdate(). With this function, I need to hit the Return key to the update to be effective.

How can I update my self.projPathLbl label the same way I update my comboItems list ( validating it with the Return key )?

a_guest
  • 34,165
  • 12
  • 64
  • 118
Vincent A
  • 85
  • 10

1 Answers1

0

Maybe one way to do that would be to implement QComboBox as a custom class with an implemented keypress event like here: PyQt Connect to KeyPressEvent

In the keypress implementation you can filter the enter key and emit your signal, which you can connect to the itemListChange slot.

phev8
  • 3,493
  • 2
  • 13
  • 23