from PyQt5.QtWidgets import QApplication, QMainWindow, QComboBox class ComboBox(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle('QComboBox Example') self.setGeometry(100, 100, 300, 200) self.combo = QComboBox(self) self.combo.addItem('Option 1') self.combo.addItem('Option 2') self.combo.addItem('Option 3') self.combo.move(50, 50) self.combo.activated[str].connect(self.select_option) self.line_edit = QLineEdit(self) self.line_edit.move(50, 100) self.show() def select_option(self, text): self.line_edit.setText(text) if __name__ == '__main__': app = QApplication([]) window = ComboBox() app.exec_()
from PyQt5.QtWidgets import QApplication, QMainWindow, QComboBox class ComboBox(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle('QComboBox Example') self.setGeometry(100, 100, 300, 200) self.combo = QComboBox(self) self.combo.setEditable(True) self.combo.addItem('Option 1') self.combo.addItem('Option 2') self.combo.addItem('Option 3') self.combo.move(50, 50) self.combo.lineEdit().textChanged[str].connect(self.select_option) self.show() def select_option(self, text): print(text) if __name__ == '__main__': app = QApplication([]) window = ComboBox() app.exec_()This example creates a QComboBox widget and makes it editable. The user can type in the QComboBox's line-edit, and the textChanged event is emitted when the text is changed. In this example, the text of the line-edit is printed to the console when it is changed. Package library: PyQt5