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 |
||
SliceChangeIconSizeProxyModel prettyqt.itemmodels.proxies.slicechangeiconsizeproxymodel |
||
SliceFilterProxyModel prettyqt.itemmodels.proxies.slicefilterproxymodel |
||
SliceCheckableProxyModel prettyqt.itemmodels.proxies.slicecheckableproxymodel |
||
SliceCheckableTreeProxyModel prettyqt.itemmodels.proxies.slicecheckableproxymodel |
||
SliceAppearanceProxyModel prettyqt.itemmodels.proxies.sliceappearanceproxymodel |
||
SliceChangeFlagsProxyModel prettyqt.itemmodels.proxies.slicechangeflagsproxymodel |
||
SliceColorValuesProxyModel prettyqt.itemmodels.proxies.slicecolorvaluesproxymodel |
||
SliceColorCategoriesProxyModel prettyqt.itemmodels.proxies.slicecolorcategoriesproxymodel |
||
SliceValueTransformationProxyModel prettyqt.itemmodels.proxies.slicevaluetransformationproxymodel |
||
SliceHighlightCurrentProxyModel prettyqt.itemmodels.proxies.slicehighlightcurrentproxymodel |
||
SliceMapRoleProxyModel prettyqt.itemmodels.proxies.slicemaproleproxymodel |
||
SliceToMarkdownProxyModel prettyqt.itemmodels.proxies.slicetomarkdownproxymodel |
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 |
||
MultiColumnFilterProxyModel prettyqt.itemmodels.proxies.multicolumnfilterproxymodel |
||
SubsetFilterProxyModel prettyqt.itemmodels.proxies.subsetfilterproxymodel |
||
ValueFilterProxyModel prettyqt.itemmodels.proxies.valuefilterproxymodel |
||
RangeFilterProxyModel prettyqt.itemmodels.proxies.rangefilterproxymodel |
||
PredicateFilterProxyModel prettyqt.itemmodels.proxies.predicatefilterproxymodel |
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. |