I am using a QCompleter with a list of countries on a QLineEdit. I am getting the selected country name when match found. But I want to trigger a function when no match is found.
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QApplication, QWidget, QVBoxLayout, QCompleter, QLineEdit
class MyWidget(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("My Widget")
self.resize(200, 100)
self.lis = ['Germany','Russia','France', 'Norway' ,'India' ,'nepal']
self.completer = QCompleter(self.lis)
self.completer.setCaseSensitivity(Qt.CaseInsensitive)
self.edit = QLineEdit()
self.edit.setCompleter(self.completer)
self.completer.activated.connect(self.on_completer_activated)
self.layout = QVBoxLayout()
self.layout.addWidget(self.edit)
self.setLayout(self.layout)
def on_completer_activated(self, text):
print(text)
if __name__ == "__main__":
app = QApplication()
widget = MyWidget()
widget.show()
app.exec()