3

I currently develop an application who support PyQt4 and PyQt5.

I have a QLineEdit with a QCompleter (with a QStringListModel). I want when user type inside QLineEdit, the completer propose matching case.

Ex: I have host-001 inside my list and user type 001, I want QLineEdit propose host-001.

I've found a way to do that with PyQt5:

host_list = ['host-001', 'host-002', 'host-003']

model = QStringListModel()
model.setStringList(hosts_list)

completer = QCompleter()
completer.setFilterMode(Qt.MatchContains)

completer.setModel(model)

line_search = QLineEdit()
line_search.setCompleter(completer)

With PyQt4 the problem is that this method does not exist, but Qt.MatchContains yes.

I've search on doc but can't found how to use it. How can I do ?

Algorys
  • 1,710
  • 2
  • 25
  • 52
  • 1
    There is no built-in equivalent in PyQt4. If you want similar functionality, you'll have to implement it yourself. (PS: the [Match Flags](https://doc.qt.io/qt-4.8/qt.html#MatchFlag-enum) aren't specifc to `QCompleter` - they're generic flags that are used by several different APIs). – ekhumoro Jan 30 '17 at 21:40
  • 1
    as @ekhumoro said, there is no built-in equivalent, here are 2 links that may help you : [link](http://www.qtcentre.org/threads/23518-How-to-change-completion-rule-of-QCompleter) and [link](http://stackoverflow.com/questions/5129211/qcompleter-custom-completion-rules) – syedelec Jan 30 '17 at 22:13

0 Answers0