Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-66547

Filter-like behavior for QCompleter

    XMLWordPrintable

Details

    Description

      I am using a combination of QLineEdit+QCompleter and QItemView to provide the user with a list of items, and a filter input for searching specific items. This works great, except that the completer only updates its model (completionModel) when the filter narrows. In the case the filter widens (e.g., backspace is pressed), this is ignored.

      Here is my workaround:

      /* Implement behavior such as updating the filter also when a character is removed.
       * It seems by default, QCompleter only updates when new characters are added. */
      QString lastText;
      connect(protSearch, &QLineEdit::textEdited, [cpl, lastText] (const QString &text) mutable {
      	if (text.length() < lastText.length()) {
      		cpl->setCompletionPrefix(text);
      	}
      	lastText = text;
      });
      

      It would be great if QCompleter would have a property that toggles the behavior between
      (a) current, only update when the filter narrows / new characters are added
      (b) new, also update in other cases

      It could be named updateStrategy ('always', 'forward').

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            ypnos Johannes Jordan
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes