PyQt QCompleter model

N

nusch

The following code:


strings=["asdad", "baasd", "casd", "caxd"]
completer = QCompleter(strings)
model = completer.model()
print model.rowCount()
model.stringList().append("test")
print model.rowCount()


prints 4 before and after appending test to stringList. What should I
do to let the model know about new data? I can save reference to
model.stringList() append keyword and after pass this reference as an
argument to setStringList then last model.rowCount() increases, but it
is not efficient when operating with e.g 20000 words in such list.

Is there better way to do this? Or is there any other method with
simply allow to add word to Qcompleter without using .stringList() >
 
D

David Boddie

The following code:

strings=["asdad", "baasd", "casd", "caxd"]
completer = QCompleter(strings)
model = completer.model()
print model.rowCount()
model.stringList().append("test")

This may not work as you expect. Although it may actually modify the list,
the model won't know about the change.
print model.rowCount()

prints 4 before and after appending test to stringList. What should I
do to let the model know about new data? I can save reference to
model.stringList() append keyword and after pass this reference as an
argument to setStringList then last model.rowCount() increases, but it
is not efficient when operating with e.g 20000 words in such list.

Ideally, you would call setStringList(), but I can see why that isn't a
good solution for you.
Is there better way to do this? Or is there any other method with
simply allow to add word to Qcompleter without using .stringList() >

Use the model API to append new rows and set new data. Something like
this should get you started:

rows = model.rowCount()
if model.insertRow(rows):
index = model.index(rows)
model.setData(index, QVariant("test"))

David
 
N

nusch

The following code:
strings=["asdad", "baasd", "casd", "caxd"]
completer = QCompleter(strings)
model = completer.model()
print model.rowCount()
model.stringList().append("test")

This may not work as you expect. Although it may actually modify the list,
the model won't know about the change.
print model.rowCount()
prints 4 before and after appending test to stringList. What should I
do to let the model know about new data? I can save reference to
model.stringList() append keyword and after pass this reference as an
argument to setStringList then last model.rowCount() increases, but it
is not efficient when operating with e.g 20000 words in such list.

Ideally, you would call setStringList(), but I can see why that isn't a
good solution for you.
Is there better way to do this? Or  is there any other method with
simply allow to add word to Qcompleter without using .stringList() >

Use the model API to append new rows and set new data. Something like
this should get you started:

  rows = model.rowCount()
  if model.insertRow(rows):
    index = model.index(rows)
    model.setData(index, QVariant("test"))

David

Thanks :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,197
Messages
2,571,040
Members
47,634
Latest member
RonnyBoelk

Latest Threads

Top