未验证 提交 1f6a42e4 编写于 作者: C Cheukfung 提交者: GitHub

fix #344

修复lineEdit添加QCompleter无法触发activated事件
上级 dee562ed
......@@ -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:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册