From c77d2d6879b74cca628584259077a265371e9f6d Mon Sep 17 00:00:00 2001 From: AlberLC Date: Sat, 18 Jun 2022 22:29:08 +0200 Subject: [PATCH] Fix tab autocomplete --- flanarunas/my_qt/combo_boxes.py | 6 ++++-- flanarunas/resources/data.json | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/flanarunas/my_qt/combo_boxes.py b/flanarunas/my_qt/combo_boxes.py index f07ba32..156bc04 100644 --- a/flanarunas/my_qt/combo_boxes.py +++ b/flanarunas/my_qt/combo_boxes.py @@ -25,6 +25,7 @@ def __init__(self, parent=None, items=None): self.lineEdit().textEdited.connect(self._set_completer_items) self.lineEdit().returnPressed.disconnect() # no add new elements at enter + self.completer.popup().activated.connect(lambda x: print(1, x)) def add_item(self, item: str): self.items += [item] @@ -34,9 +35,10 @@ def delete_item(self, name: str): self.items = self._items def event(self, event: QtCore.QEvent) -> bool: - if isinstance(event, QtGui.QKeyEvent) and event.key() == QtCore.Qt.Key_Tab: + if isinstance(event, QtGui.QKeyEvent) and event.key() == QtCore.Qt.Key_Tab and event.type() == QtCore.QEvent.KeyPress: # noinspection PyUnresolvedReferences - self.completer.activated.emit(self.completer.currentCompletion()) + self.completer.activated.emit(self.completer.popup().model().data(self.completer.popup().currentIndex())) + self.setFocus() return super().event(event) diff --git a/flanarunas/resources/data.json b/flanarunas/resources/data.json index 9e26dfe..0967ef4 100644 --- a/flanarunas/resources/data.json +++ b/flanarunas/resources/data.json @@ -1 +1 @@ -{} \ No newline at end of file +{}