Proxy models
Every class containing the AbstractItemViewMixin (widgets.TreeView, widgets.TableView, ...)
has quick access to proxy superpowers hidden behind the "proxifier" attribute.
The following section will give an overview about the included proxies and how to apply them.
Slice proxies
PrettyQt introduces a base proxy model which allows its subclasses to be selectively applied to
the source model by using python slicing syntax.
They can get quickly set up via our Proxifier.
Example:
model = MyTableModel()
table = widgets.TableView()
table.set_model(model)
# lets change the appearance a bit.
# Set the font color of column 2 and 3 to red and font to Courier.
table.proxifier[:, 2:4].style(foreground="red", font="Courier")
# Cut off last column and only show last 50 lines.
table.proxifier[:50, :-1].filter()
# Set first 20 lines of these 50 lines to read_only
table.proxifier[:20, :].change_flags(editable=False)
# Make first column checkable and trigger callback on checkstate change.
table.proxifier[0].make_checkable(callback=my_callback)
Every call here basically adds another ProxyModel layer (all based on SliceIdentityProxyModel).
The proxy models should all perform very well with large tables since they never need to loop over the whole column / row range.
The proxifier attribute basically gives quick access to set up these proxies.
basically equals something like:proxy = SliceFilterProxyModel(indexer=(slice(None, -1, 1), slice(5, None, 2)))
proxy.setSourceModel(table.model())
table.set_model(proxy)
If you want to apply a slice proxy to all cells of the model, use slices without start and stop values:
Here is a short overview of the included slice proxies:
| Name | Children | Inherits |
|---|---|---|
| SliceDisplayTextProxyModel prettyqt.itemmodels.proxies.slicedisplaytextproxymodel Proxy model to convert and format non-str values for the DisplayRole. |
||
| SliceChangeIconSizeProxyModel prettyqt.itemmodels.proxies.slicechangeiconsizeproxymodel Proxy model which changes the icon size of the Decoration role. |
||
| SliceFilterProxyModel prettyqt.itemmodels.proxies.slicefilterproxymodel Proxy model to filter an item view based on python slicing syntax. |
||
| SliceCheckableProxyModel prettyqt.itemmodels.proxies.slicecheckableproxymodel Proxy model to make a model checkable. |
||
| SliceCheckableTreeProxyModel prettyqt.itemmodels.proxies.slicecheckableproxymodel Proxy model to make a tree model checkable. |
||
| SliceAppearanceProxyModel prettyqt.itemmodels.proxies.sliceappearanceproxymodel |
||
| SliceChangeFlagsProxyModel prettyqt.itemmodels.proxies.slicechangeflagsproxymodel Proxy model to selectively change the ItemFlags of the source model. |
||
| SliceColorValuesProxyModel prettyqt.itemmodels.proxies.slicecolorvaluesproxymodel Model to color cells of a numerical table based on their value. |
||
| SliceColorCategoriesProxyModel prettyqt.itemmodels.proxies.slicecolorcategoriesproxymodel Proxy model to apply coloring to categories. |
||
| SliceValueTransformationProxyModel prettyqt.itemmodels.proxies.slicevaluetransformationproxymodel A proxy model which transforms cell contents based on a Callable. |
||
| SliceHighlightCurrentProxyModel prettyqt.itemmodels.proxies.slicehighlightcurrentproxymodel Proxy model which highlights all cells with same data as current index. |
||
| SliceMapRoleProxyModel prettyqt.itemmodels.proxies.slicemaproleproxymodel Proxy model for mapping one role to another. |
||
| SliceToMarkdownProxyModel prettyqt.itemmodels.proxies.slicetomarkdownproxymodel Proxy model which transforms cell contents to markdown. |
Sort/Filter proxies.
In addition to the mentioned SliceFilterProxyModel, PrettyQt also contains several proxies based on QSortFilterProxyModel. These can be more powerful than the mentioned SliceFilterProxyModel, but scale with O(1) in respect to row / column count. (meaning that things might get slower for very large tables or when several proxies are layered on top of each other.) Some of these proxies might partly overlap in functionality, but theres always a best one one for each use case to pick.
| Name | Children | Inherits |
|---|---|---|
| FuzzyFilterProxyModel prettyqt.itemmodels.proxies.fuzzyfilterproxymodel A FilterProxyModel which sorts the results based on a matching score. |
||
| MultiColumnFilterProxyModel prettyqt.itemmodels.proxies.multicolumnfilterproxymodel A SortFilterProxyModel which filters based on multiple columns in one go. |
||
| SubsetFilterProxyModel prettyqt.itemmodels.proxies.subsetfilterproxymodel A FilterProxyModel to filter based on slices, ranges, indexes or Callables. |
||
| ValueFilterProxyModel prettyqt.itemmodels.proxies.valuefilterproxymodel Proxy model for filtering based on non-str values. |
||
| RangeFilterProxyModel prettyqt.itemmodels.proxies.rangefilterproxymodel |
||
| PredicateFilterProxyModel prettyqt.itemmodels.proxies.predicatefilterproxymodel A simple filter proxy model with settable filter predicates. |
Reshape / Styling proxies
| Proxy | Description |
|---|---|
TableToListProxyModel |
Stack all columns into one single column |
FlattenTreeProxyModel |
Moves all rows up to the root level. |
MeltProxyModel |
Unpivot a Table from wide to long format. |
ColumnOrderProxyModel |
Reorder columns and hide columns. |
ChangeHeadersProxyModel |
Change horizontal / vertical headers. |
AppearanceProxyModel |
Proxy model to change styling. |
Other Proxies
| Proxy | Description |
|---|---|
HighlightMouseProxymodel |
Highlight regions the mouse cursor is hovering over. |
Miscellaneous
| Class | Description |
|---|---|
ProxyMapper |
A helper for mapping indexes between proxies in any proxy tree. |
LinkedSelectionModel |
A SelectionModel which keeps indexes of any amount of proxies / source models in sync. |
ProxyComparerWidget |
A widget to compare a proxy chain, useful for debugging. |