-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutocomplete.py
More file actions
50 lines (36 loc) · 1.32 KB
/
Autocomplete.py
File metadata and controls
50 lines (36 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import sys
from PyQt6.QtGui import *
from PyQt6.QtWidgets import *
class Demo(QWidget):
def __init__(self):
super(Demo, self).__init__()
self.resize(1000, 500)
names = ['Peter', 'Kelvin', 'James', 'Karen', 'Njeri', 'Faith', 'Amos', "Lydia", 'Carol', 'Jared', 'Jane',
'Janee', 'Jamrock']
font = QFont('Open Sans', 12)
lay = QVBoxLayout()
self.input = QLineEdit()
self.input.setFixedHeight(50)
self.input.setFont(font)
self.input.editingFinished.connect(self.addEntry)
lay.addWidget(self.input)
self.model = QStandardItemModel()
for i in names:
self.model.appendRow(QStandardItem(i))
completer = QCompleter(self.model, self)
self.input.setCompleter(completer)
self.console = QTextEdit()
self.console.setFont(font)
lay.addWidget(self.console)
self.setLayout(lay)
def addEntry(self):
entryItem = self.input.text()
self.input.clear()
self.console.append(entryItem)
if not self.model.findItems(entryItem):
self.model.appendRow(QStandardItem(entryItem))
if __name__ == '__main__':
app = QApplication(sys.argv)
dm = Demo()
dm.show()
sys.exit(app.exec())