diff --git a/qfluentwidgets/components/widgets/line_edit.py b/qfluentwidgets/components/widgets/line_edit.py index 9ade43e4985465ae87140be83f03609e48e7b26b..67d7bd5a366f69514a1b753ce68c0f3536257c96 100644 --- a/qfluentwidgets/components/widgets/line_edit.py +++ b/qfluentwidgets/components/widgets/line_edit.py @@ -127,6 +127,7 @@ class LineEdit(QLineEdit): # create menu if not self._completerMenu: self._completerMenu = CompleterMenu(self) + self._completerMenu.activated.connect(self._completer.activated) # add menu items self.completer().setCompletionPrefix(self.text()) @@ -164,6 +165,8 @@ class LineEdit(QLineEdit): class CompleterMenu(RoundMenu): """ Completer menu """ + activated = pyqtSignal(str) + def __init__(self, lineEdit: LineEdit): super().__init__() self.items = [] @@ -192,7 +195,7 @@ class CompleterMenu(RoundMenu): # add items for i in items: - self.addAction(QAction(i, triggered=lambda c, x=i: self.lineEdit.setText(x))) + self.addAction(QAction(i, triggered=lambda c, x=i: self.__onItemSelected(x))) return True @@ -207,11 +210,15 @@ class CompleterMenu(RoundMenu): if e.key() == Qt.Key_Escape: self.close() if e.key() in [Qt.Key_Enter, Qt.Key_Return] and self.view.currentRow() >= 0: - self.lineEdit.setText(self.view.currentItem().text()) + self.__onItemSelected(self.view.currentItem().text()) self.close() return super().eventFilter(obj, e) + def __onItemSelected(self, text): + self.lineEdit.setText(text) + self.activated.emit(text) + def popup(self): """ show menu """ if not self.items: