PyQt QCompleter model
David Boddie
david at boddie.org.uk
Wed Sep 16 20:40:17 EDT 2009
On Thursday 17 September 2009 01:14, nusch wrote:
> 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
More information about the Python-list
mailing list