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.
FXSortFilterProxyModel
Bases: QSortFilterProxyModel
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
__filterAcceptsRow
Determine whether a row should be accepted by the filter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_row |
int
|
The source row index. |
required |
source_parent |
QModelIndex
|
The source parent index. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
|
__init__
Initialize the FXSortFilterProxyModel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ratio |
float
|
The ratio threshold for filtering. |
0.5
|
color_match |
bool
|
Whether to enable color matching. |
True
|
parent |
Optional[QWidget]
|
The parent widget. |
None
|
data
Get the data for a given role and index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index |
QModelIndex
|
The model index. |
required |
role |
int
|
The role for which data is requested. |
DisplayRole
|
Returns:
Type | Description |
---|---|
Optional[QBrush]
|
The data for the given role and index. |
filterAcceptsColumn
Determine whether a column should be accepted by the filter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_column |
int
|
The source column index. |
required |
source_parent |
QModelIndex
|
The source parent index. |
required |
Returns:
Type | Description |
---|---|
bool
|
|
filterAcceptsRow
Determine whether a row should be accepted by the filter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_row |
int
|
The source row index. |
required |
source_parent |
QModelIndex
|
The source parent index. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
|
lessThan
Compare two indices to determine their order.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
left |
QModelIndex
|
The left index. |
required |
right |
QModelIndex
|
The right index. |
required |
Returns:
Type | Description |
---|---|
bool
|
|
bool
|
|
set_color_match
Set whether to enable color matching.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
color_match |
bool
|
Whether to enable color matching. |
required |
set_filter_text
Set the filter text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text |
str
|
The filter text. |
required |
set_ratio
Set the ratio threshold for filtering.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ratio |
float
|
The ratio threshold. |
required |