PyQt supports autocomplete. If you type in a text box (QLineEdit), it can make suggestions. Those suggestions are recommended from a list.

This example adds auto complete to a QLineEdit text box.

auto complete QLineEdit

image: tabs showing in a pyqt window.

Auto complete

QLineEdit Auto Complete Example

Start by creating a list of options (names) and creates a completer = QCompleter(names).

A line edit is created with the line self.lineedit = QLineEdit(). The line edit otherwise works as normal.

The suggestions are added with self.lineedit.setCompleter(completer).

If you forget the last line, the QCompleter and QLineEdit are not connected, meaning there is no auto completion.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from PyQt5.QtWidgets import *
import sys

class Window(QWidget):
def __init__(self):
QWidget.__init__(self)
layout = QGridLayout()
self.setLayout(layout)

# auto complete options
names = ["Apple", "Alps", "Berry", "Cherry" ]
completer = QCompleter(names)

# create line edit and add auto complete
self.lineedit = QLineEdit()
self.lineedit.setCompleter(completer)
layout.addWidget(self.lineedit, 0, 0)

app = QApplication(sys.argv)
screen = Window()
screen.show()
sys.exit(app.exec_())