Skip to content

Qt Search Comboboxes#

Search-first combobox variants for inline filtering and type-ahead selection.

Screenshot#

qt combobox search

Example#

Source: examples/qt_combobox_search.py

"""Search combobox widgets."""

from qtpy.QtWidgets import QApplication, QLabel, QVBoxLayout, QWidget

from qtextra.config import THEMES
from qtextra.widgets.qt_combobox_search import QtSearchableComboBox, QtSearchComboBox

OPTIONS = [
    "Alpha project",
    "Beta release",
    "Critical bugfix",
    "Design review",
    "Docs pass",
    "Nightly build",
]

app = QApplication([])

widget = QWidget()
widget.setMinimumWidth(520)
THEMES.apply(widget)

layout = QVBoxLayout(widget)
layout.addWidget(QLabel("QtSearchableComboBox"))
searchable = QtSearchableComboBox(widget)
searchable.addItems(OPTIONS)
searchable.setCurrentText("Design review")
layout.addWidget(searchable)

layout.addWidget(QLabel("QtSearchComboBox"))
search = QtSearchComboBox(parent=widget)
search.addItems(OPTIONS)
search.set_current_text("Docs pass")
layout.addWidget(search)

layout.addStretch(1)
widget.show()

app.exec_()

Notes#

  • QtSearchComboBox uses a custom popup panel with its own search field.
  • QtSearchableComboBox extends QComboBox with completer-based filtering.

API#

Qt Class#

QWidget

Signals#

currentTextChanged#

Methods#

Combobox with a live-filter search field in the dropdown.

addItems = set_items class-attribute instance-attribute #

current_text() -> str #

Return current text displayed.

set_current_text(t: str) #

Set current text to be displayed.

set_items(items: list[str]) #

Set items to be displayed.

Qt Class#

QComboBox

Methods#

Searchable combobox.

onActivated = on_activated class-attribute instance-attribute #

on_activated(value: str) -> None #

On activated.