Important: Please read the Qt Code of Conduct -

PyQT5 - How to use QCompleter, QGIS Plugin

  • I'm trying to use QCompleter to get something like in the image. The code seems pretty simple, but in my dialog nothing happens. Is there some problem in this code? The dialog is created using Qt Designer.
    alt text

    import sys
    from PyQt5.QtWidgets import QAction, QFileDialog, QApplication, QWidget, QVBoxLayout, QLineEdit, QCompleter
    def run(self):
      if self.first_start == True:
        self.first_start = False
        self.dlg = SelectFeatureDialog()
        strList = ['Python', 'PyQt5', 'Qt', 'QML']   
        completer = QCompleter(strList)
      result = self.dlg.exec_()
      if result:

    EDIT: are there some errors in these settings?
    Annotazione 2019-11-29 110954.jpg

  • Lifetime Qt Champion


    This example works as expected:

    import sys
    from PyQt5.QtCore import Qt
    from PyQt5.QtWidgets import QApplication, QLineEdit, QCompleter, QDialog, QVBoxLayout
    if __name__ == "__main__":
        app = QApplication(sys.argv)
        line_edit = QLineEdit()
        completer = QCompleter(["Apple", "Alps"])
        dialog = QDialog()
        layout = QVBoxLayout(dialog)

    What version of PyQt5 are you using ?

Log in to reply