fxcore
fxcore
¶
Wrapper around the QtCore module for fxgui.
This module provides core functionality and custom classes to enhance the use
of QtCore within the fxgui framework.
Classes:
| Name | Description |
|---|---|
FXSortFilterProxyModel |
A filter model using fuzzy matching based on SequenceMatcher similarity ratios. |
Examples:
Using FXSortFilterProxyModel with a search bar:
>>> from fxgui.fxcore import FXSortFilterProxyModel
>>> proxy = FXSortFilterProxyModel(ratio=0.6)
>>> proxy.setSourceModel(my_model)
>>> search_bar.textChanged.connect(proxy.set_filter_text)
Classes¶
FXSortFilterProxyModel
¶
FXSortFilterProxyModel(
ratio: float = 0.5,
color_match: bool = True,
parent: Optional[QWidget] = None,
)
Bases: QSortFilterProxyModel
flowchart TD
fxgui.fxcore.FXSortFilterProxyModel[FXSortFilterProxyModel]
click fxgui.fxcore.FXSortFilterProxyModel href "" "fxgui.fxcore.FXSortFilterProxyModel"
A filter model that uses SequenceMatcher to filter items based on
a similarity ratio. The similarity ratio is a value between 0 and 1,
where 1 indicates a perfect match.
Examples:
Filter a list of items using the FXSortFilterProxyModel
>>> items = ["apple", "banana", "cherry", "date"]
>>> search_bar = QLineEdit()
>>> view = QListView()
>>> model = QStringListModel()
>>> model.setStringList(items)
>>> proxy = FXSortFilterProxyModel()
>>> proxy.setSourceModel(model)
>>> view.setModel(proxy)
>>> search_bar.textChanged.connect(proxy.set_filter_text)
Notes
Base code from Alex Telford: LinkedIn post
Initialize the FXSortFilterProxyModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
float
|
The ratio threshold for filtering. |
0.5
|
|
bool
|
Whether to enable color matching. |
True
|
|
Optional[QWidget]
|
The parent widget. |
None
|
Methods:
| Name | Description |
|---|---|
data |
Get the data for a given role and index. |
filterAcceptsRow |
Determine whether a row should be accepted by the filter. |
lessThan |
Compare two indices to determine their order. |
set_color_match |
Set whether to enable color matching. |
set_filter_text |
Set the filter text. |
set_ratio |
Set the ratio threshold for filtering. |
set_show_all |
Set whether to show all items regardless of the filter. |
Functions¶
data
¶
filterAcceptsRow
¶
filterAcceptsRow(source_row: int, source_parent: QModelIndex) -> bool
lessThan
¶
set_color_match
¶
set_color_match(color_match: bool) -> None