Skip to content

SubsequenceCompleter

Qt Base Class: QCompleter

Signature: QCompleter(self, completions: Sequence[str], parent: Optional[PySide6.QtCore.QObject] = None) -> None QCompleter(self, model: PySide6.QtCore.QAbstractItemModel, parent: Optional[PySide6.QtCore.QObject] = None) -> None QCompleter(self, parent: Optional[PySide6.QtCore.QObject] = None) -> None

Base classes

Name Children Inherits
Completer
prettyqt.widgets.completer

⋔ Inheritance diagram

graph TD
  1473367158480["custom_widgets.SubsequenceCompleter"]
  1473296325184["widgets.Completer"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473293754608["QtWidgets.QCompleter"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473296325184 --> 1473367158480
  1473299815024 --> 1473296325184
  140713234304496 --> 1473299815024
  1473293754608 --> 1473296325184
  1473288842240 --> 1473293754608
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208

🛈 DocStrings

Bases: Completer

QCompleter specialised for subsequence matching.

Source code in prettyqt\custom_widgets\subsequencecompleter.py
class SubsequenceCompleter(widgets.Completer):
    """QCompleter specialised for subsequence matching."""

    def __init__(self, *args):
        super().__init__(*args)
        self.completion_search_term = ""
        self.source_model = None
        self.set_completion_mode("unfiltered_popup")
        self.proxy_model = itemmodels.SubsequenceSortFilterProxyModel(parent=self)
        self.proxy_model.setFilterCaseSensitivity(self.caseSensitivity())
        self.set_case_sensitive(False)
        self._force_next_update = True
        self.path_updated.connect(self._on_path_updated)
        self.setCompletionRole(constants.DISPLAY_ROLE)

    def setModel(self, model: core.QAbstractItemModel):
        self.source_model = model
        self.proxy_model = itemmodels.SubsequenceSortFilterProxyModel(parent=self)
        self.proxy_model.setFilterCaseSensitivity(self.caseSensitivity())
        self.proxy_model.set_search_term(self.completion_search_term)
        self.proxy_model.setSourceModel(self.source_model)
        super().setModel(self.proxy_model)
        self.proxy_model.invalidateRowsFilter()
        # self.proxy_model.sort(0)
        self._force_next_update = True

    # def __getattr__(self, key):
    #     return getattr(self.proxy_model, key)

    def set_case_sensitive(self, value: bool):
        super().set_case_sensitive(value)
        self.proxy_model.set_filter_case_sensitive(value)

    def _on_path_updated(self, path: str):
        if path == self.completion_search_term:
            return None
        self.completion_search_term = path
        count = self.completionCount()
        if count or len(self.completion_search_term) <= 1 or self._force_next_update:
            self.proxy_model.set_search_term(self.completion_search_term)
        if count > 1:
            self.proxy_model.sort(0)
        self._force_next_update = False
        self.proxy_model.invalidateRowsFilter()  # force sorting/filtering

⌗ Property table

Qt Property Type Doc
objectName QString
completionPrefix QString
modelSorting QCompleter::ModelSorting
filterMode QFlags
completionMode QCompleter::CompletionMode
completionColumn int
completionRole int
maxVisibleItems int
caseSensitivity Qt::CaseSensitivity
wrapAround bool