Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is there a QCompleter "initiated" signal?

Is there a QCompleter "initiated" signal?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 969 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by JonB
    #1

    Qt5. Using a QCompleter(QStringList), with QCompleter.setCompletionMode(QCompleter.PopupCompletion). Attached to a QLineEdit.

    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 the QCompleter? (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 the QLineEdit instead (yuck)?

    • Second, I see from QCompleter(QStringList) that QStringList items 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 QCompleter at all initially, then look at the QLineEdit for something like click/character typed, and only at that instant create the QCompleter populated 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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You can also give it a QAbstractItemModel so 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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      JonBJ 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        You can also give it a QAbstractItemModel so 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.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        So it seems there isn't any notification from QCompleter that 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; QCompleter could 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't rowCount() 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 the QCompleter after all. If users moan it's a delay, I'll say it's a Qt limitation... :)

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You can use an event filter on the view used by the QComboBox and react on its show event.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          JonBJ 1 Reply Last reply
          0
          • SGaistS SGaist

            You can use an event filter on the view used by the QComboBox and react on its show event.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @SGaist
            But this is a QCompleter, and it can have various CompletionModes, 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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved