fuzzy_search_list
_fuzzy_search_list
¶
Fuzzy search list widget with relevance-based filtering and sorting.
Classes:
| Name | Description |
|---|---|
FXFuzzySearchList |
A searchable list widget with fuzzy matching capabilities. |
Functions:
| Name | Description |
|---|---|
example |
Run an example demonstrating the FXFuzzySearchList widget. |
Classes¶
FXFuzzySearchList
¶
FXFuzzySearchList(
parent: Optional[QWidget] = None,
placeholder: str = "Search...",
ratio: float = 0.5,
show_ratio_slider: bool = False,
color_match: bool = True,
)
Bases: FXThemeAware, QWidget
flowchart TD
fxgui.fxwidgets._fuzzy_search_list.FXFuzzySearchList[FXFuzzySearchList]
fxgui.fxstyle.FXThemeAware[FXThemeAware]
fxgui.fxstyle.FXThemeAware --> fxgui.fxwidgets._fuzzy_search_list.FXFuzzySearchList
click fxgui.fxwidgets._fuzzy_search_list.FXFuzzySearchList href "" "fxgui.fxwidgets._fuzzy_search_list.FXFuzzySearchList"
click fxgui.fxstyle.FXThemeAware href "" "fxgui.fxstyle.FXThemeAware"
A searchable list widget with fuzzy matching capabilities.
This widget combines a search bar with a list view that uses fuzzy matching to filter and sort items by relevance. Items are colored based on their match quality (green for good matches, red for poor matches).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Optional[QWidget]
|
Parent widget. |
None
|
|
str
|
Placeholder text for the search input. |
'Search...'
|
|
float
|
Initial similarity ratio threshold (0.0 to 1.0). |
0.5
|
|
bool
|
Whether to show the ratio adjustment slider. |
False
|
|
bool
|
Whether to color items based on match quality. |
True
|
Signals
item_selected: Emitted when an item is clicked. Passes the item text. item_double_clicked: Emitted when an item is double-clicked. Passes the item text. item_activated: Emitted when Enter is pressed on an item. Passes the item text. selection_changed: Emitted when the selection changes. Passes a list of selected item texts.
Examples:
Basic usage with a list of strings:
>>> fuzzy_list = FXFuzzySearchList(placeholder="Search fruits...")
>>> fuzzy_list.set_items(["apple", "apricot", "banana", "cherry"])
>>> fuzzy_list.item_selected.connect(lambda text: print(f"Selected: {text}"))
With ratio slider for user adjustment:
>>> fuzzy_list = FXFuzzySearchList(show_ratio_slider=True, ratio=0.6)
>>> fuzzy_list.set_items(["character_hero", "character_villain", "prop_chair"])
Methods:
| Name | Description |
|---|---|
add_item |
Add a single item to the list. |
clear |
Clear all items from the list. |
clear_search |
Clear the search input. |
remove_item |
Remove an item from the list by its text. |
select_item |
Select an item by its text. |
setFocus |
Set focus to the search input. |
set_color_match |
Enable or disable color-coded match quality. |
set_items |
Set the list items from a list of strings. |
set_placeholder |
Set the search bar placeholder text. |
set_selection_mode |
Set the list view selection mode. |
show_ratio_slider |
Show or hide the ratio adjustment slider. |
Attributes:
| Name | Type | Description |
|---|---|---|
current_item |
Optional[str]
|
Return the current item text. |
items |
List[str]
|
Return all items in the source model. |
list_view |
QListView
|
Return the list view for advanced customization. |
proxy_model |
FXSortFilterProxyModel
|
Return the proxy model for advanced customization. |
ratio |
float
|
Return the current similarity ratio threshold. |
search_text |
str
|
Return the current search text. |
selected_items |
List[str]
|
Return currently selected items. |
source_model |
QStandardItemModel
|
Return the source model for advanced customization. |
visible_items |
List[str]
|
Return currently visible (filtered) items. |
Attributes¶
current_item
property
¶
items
property
¶
list_view
property
¶
Return the list view for advanced customization.
Returns:
| Type | Description |
|---|---|
QListView
|
The underlying QListView. |
proxy_model
property
¶
proxy_model: FXSortFilterProxyModel
Return the proxy model for advanced customization.
Returns:
| Type | Description |
|---|---|
FXSortFilterProxyModel
|
The underlying FXSortFilterProxyModel. |
ratio
property
writable
¶
ratio: float
Return the current similarity ratio threshold.
Returns:
| Type | Description |
|---|---|
float
|
The ratio threshold (0.0 to 1.0). |
selected_items
property
¶
source_model
property
¶
Return the source model for advanced customization.
Returns:
| Type | Description |
|---|---|
QStandardItemModel
|
The underlying QStandardItemModel. |