PDA

View Full Version : Highlight item in the list in accordance to text input



salik89
29th January 2014, 14:36
I am trying to highlight the item in my list upon the input of the text in the LineEdit but however, not only am I unable to get it to work but it also does not highlights the item in the List. Am I writing it wrong somewhere? Any advices?



fruitsList = QListWidget()
list01 = ['Apple','Pear','Orange','Grape','Lychee']
self.fruitsList.addItems(list01)

textInput = QLineEdit()
fruitTxt = str(textInput)

self.connect(self.textInput,('returnPressed()'), self.updateSelect)

def updateSelect(self):
self.fruitsList.findItems(str(fruitTxt), flags = Qt.MatchExactly)
self.fruitsList.setCurrentIndex(0)

anda_skoa
29th January 2014, 18:55
findItems() returns you a list of the items matching your search string.

In your case you would then iterate over that list and call setSelected(true)

Cheers,
_