Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/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)
        self.dlg.lineEdit.setCompleter(completer)  
    
      self.dlg.show()
      result = self.dlg.exec_()
      if result:
        pass
    

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


  • Lifetime Qt Champion

    Hi,

    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"])
        completer.setCaseSensitivity(Qt.CaseInsensitive)
        line_edit.setCompleter(completer)
        dialog = QDialog()
        layout = QVBoxLayout(dialog)
        layout.addWidget(line_edit)
        dialog.show()
        sys.exit(app.exec_())
    

    What version of PyQt5 are you using ?


Log in to reply