...
def __init__(self):
self.isActive = False
def eventFilter(self, object, event):
if event.
type() == QEvent.
KeyPress: if event.modifiers() and Qt.ControlModifier:
if event.key() == Qt.Key_Return:
if self.isActive:
self.isActive = False
self.emit(SIGNAL("autoCompleteToggled(bool)"), False)
else:
self.isActive = True
self.emit(SIGNAL("autoCompleteToggled(bool)"), True)
return True
return QObject.
eventFilter(self, object, event
) ...
class DeckEditorWindow
(QMainWindow, Ui_DeckEditorWindow
):
def __init__(self, parent=None):
...
self.autoCompleteFilter = AutoCompleteFilter()
self.connect(self.autoCompleteFilter,
SIGNAL("autoCompleteToggled(bool)"),
self.autoComplete)
self.filtersLineEdit.installEventFilter(self.autoCompleteFilter)
...
def autoComplete(self, isActive):
if isActive:
self.completer.setModel(self.resultsModel)
self.
completer.
setModelSorting(QCompleter.
CaseInsensitivelySortedModel) if isActive:
self.
completer.
setModel(self.
resultsModel) self.
completer.
setModelSorting(QCompleter.
CaseInsensitivelySortedModel) self.completer.setCaseSensitivity(Qt.CaseInsensitive)
self.completer.setCompletionRole(Qt.DisplayRole)
self.filtersLineEdit.setCompleter(self.completer)
self.completer.complete()
else:
self.filtersLineEdit.setCompleter(None)
...
...
class AutoCompleteFilter(QObject):
def __init__(self):
QObject.__init__(self)
self.isActive = False
def eventFilter(self, object, event):
if event.type() == QEvent.KeyPress:
if event.modifiers() and Qt.ControlModifier:
if event.key() == Qt.Key_Return:
if self.isActive:
self.isActive = False
self.emit(SIGNAL("autoCompleteToggled(bool)"), False)
else:
self.isActive = True
self.emit(SIGNAL("autoCompleteToggled(bool)"), True)
return True
return QObject.eventFilter(self, object, event)
...
class DeckEditorWindow(QMainWindow, Ui_DeckEditorWindow):
def __init__(self, parent=None):
...
self.autoCompleteFilter = AutoCompleteFilter()
self.connect(self.autoCompleteFilter,
SIGNAL("autoCompleteToggled(bool)"),
self.autoComplete)
self.filtersLineEdit.installEventFilter(self.autoCompleteFilter)
...
def autoComplete(self, isActive):
if isActive:
self.completer = QCompleter(self)
self.completer.setModel(self.resultsModel)
self.completer.setModelSorting(QCompleter.CaseInsensitivelySortedModel)
if isActive:
self.completer = QCompleter(self)
self.completer.setModel(self.resultsModel) self.completer.setModelSorting(QCompleter.CaseInsensitivelySortedModel)
self.completer.setCaseSensitivity(Qt.CaseInsensitive)
self.completer.setCompletionRole(Qt.DisplayRole)
self.filtersLineEdit.setCompleter(self.completer)
self.completer.complete()
else:
self.filtersLineEdit.setCompleter(None)
...
To copy to clipboard, switch view to plain text mode
Bookmarks