Is there a QCompleter "initiated" signal?
-
Qt5. Using a
QCompleter(QStringList), withQCompleter.setCompletionMode(QCompleter.PopupCompletion). Attached to aQLineEdit.My string list is "expensive" to populate. So while I attach the completer to the line edit early, I'd like to delay population of the list till the very last moment, which I take to be when the user types a character into the line edit or whatever and the first attempt at a completion is made? So I'd like something like:
# assign empty list initially completer = QCompleter([]) # connect the "initiated" signal to populate the items at that point completer.firsttimeattemptcompletesignal.connect(lambda: completer.getNewStringList())I see two problems; they may be inter-related:
-
First & foremost, what can I use for
completer.firsttimeattemptcompletesignal? I see no signal from theQCompleter? (Also bear in mind that at this point the possible completions will be empty, so I'd need a signal that would still fire even if no completions are available.) Do I have to do something on theQLineEditinstead (yuck)? -
Second, I see from
QCompleter(QStringList)thatQStringListitems is only available during constructor, cannot be added to later, right? So to achieve change of items I'd have to change over to model? (And I'm not sure whether there aren't issues with "dynamic repopulation of model during completion" in any case?)
If it all gets too tricky, should I perhaps not create the
QCompleterat all initially, then look at theQLineEditfor something like click/character typed, and only at that instant create theQCompleterpopulated with strings read at that point, attach it to line edit, and then do what to get to how it would be if the completer had been attached before the click/key stroke? -
-
Hi,
You can also give it a
QAbstractItemModelso you could create a small QAbstractListModel subclass and when data is called check whether you already loaded your list and do it at that time.On a parallel idea, you could copy QFileSystemModel and load your data in a separated thread.
-
Hi,
You can also give it a
QAbstractItemModelso you could create a small QAbstractListModel subclass and when data is called check whether you already loaded your list and do it at that time.On a parallel idea, you could copy QFileSystemModel and load your data in a separated thread.
So it seems there isn't any notification from
QCompleterthat it needs the completion list now, so go get it, which is a shame. (Think of comboboxes: it's not uncommon to have them populated "on demand", so you get a notification as the user clicks the "expand list arrow" to do the population;QCompletercould do with that, the list is liable to be even longer/more expensive than what you'd store in a combobox.)@SGaist
Yours is probably the best way to go, but I'm losing the will to live on this.when data is called check whether you already loaded your list
I'd need a definitive list for which functions then, to be certain I populate in time regardless of what user does. I suspect just
data()will be too late, won'trowCount()likely get called earlier? Who knows. So given that Qt docs don't give me that explicitly, I've given up, collapsed in a heap, and pre-populated theQCompleterafter all. If users moan it's a delay, I'll say it's a Qt limitation... :) -
You can use an event filter on the view used by the QComboBox and react on its show event.
-
@SGaist
But this is aQCompleter, and it can have variousCompletionModes, not sure how they would work with events? Also I'm thinking any show event might come after a call wanting the possible completions before it tries to show them, and that would be too late.