2

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.

enter image description here

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()

Are there some errors in these settings?

enter image description here


I'm very stupid, the completer works but I was trying with the lowercase, while in my string's list the first letter is always uppercase.

Now I'm wondering how to ignore the case?

  • Does the script have 'dialog event loop' line after self.dlg.show(), like result = self.dlg.exec_()? – Kadir Şahbaz Nov 28 '19 at 19:08
  • yes, sorry I did not write it – Lorenzo Nov 28 '19 at 19:43
2

In response to OP's edit to the question...

to make the completer case insensitive, use the setCaseSensitivity() method:

strList = ['Python', 'PyQt5', 'Qt', 'QML']   
completer = QCompleter(strList)
completer.setCaseSensitivity(Qt.CaseInsensitive)
self.dlg.lineEdit.setCompleter(completer)
| improve this answer | |
  • Hi thanks for you answer, did you read my Edit2? – Lorenzo Nov 29 '19 at 10:33
  • @Lorenzo, I just edited my answer! – Ben W Nov 29 '19 at 10:45
  • 1
    Hi, you are very kind and I'm very noob. What should I import? It says "Undefined variable 'Qt'. Thank you again – Lorenzo Nov 29 '19 at 10:47
  • 1
    I solved using completer.setCaseSensitivity(0) – Lorenzo Nov 29 '19 at 11:03
  • Great @Lorenzo, otherwise you can just add it to the first line of import statements: from PyQt5.QtCore import Qt, etc – Ben W Nov 29 '19 at 11:04
2

I couldn't find the reason about the problem, but if you remove 'dialog event loop' line, then, string-completion facilities works.

enter image description here

#

    self.dlg.show()

    # REMOVE FOLLOWING LINES
    result = self.dlg.exec_()
    if result:
        pass
| improve this answer | |
  • Thank you for your answer, but if I remove that lines then my plugin becomes useless, because the processing is after that. – Lorenzo Nov 28 '19 at 19:56
  • @Kadir Şahbaz, I upvoted your answer. I hope you forgive me for adding my answer with the benefit of the OP's question edits!! – Ben W Nov 29 '19 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.