Skip to content

SliceChangeIconSizeProxyModel

Qt Base Class: QIdentityProxyModel

Signature: QIdentityProxyModel(self, parent: Optional[PySide6.QtCore.QObject] = None) -> None

Base classes

Name Children Inherits
SliceIdentityProxyModel
prettyqt.itemmodels.proxies.sliceidentityproxymodel

⋔ Inheritance diagram

graph TD
  1473290714016["itemmodels.SliceChangeIconSizeProxyModel"]
  1473290716944["itemmodels.SliceIdentityProxyModel"]
  1473299892128["core.IdentityProxyModel"]
  1473299903840["core.AbstractProxyModelMixin"]
  1473299890176["core.AbstractItemModelMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473289064768["QtCore.QIdentityProxyModel"]
  1473289061840["QtCore.QAbstractProxyModel"]
  1473289050128["QtCore.QAbstractItemModel"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473290716944 --> 1473290714016
  1473299892128 --> 1473290716944
  1473299903840 --> 1473299892128
  1473299890176 --> 1473299903840
  1473299815024 --> 1473299890176
  140713234304496 --> 1473299815024
  1473289064768 --> 1473299892128
  1473289061840 --> 1473289064768
  1473289050128 --> 1473289061840
  1473288842240 --> 1473289050128
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208

🛈 DocStrings

Bases: SliceIdentityProxyModel

Proxy model which changes the icon size of the Decoration role.

Supports QColors, QPixmaps and QIcons in DecorationRole.

Example

model = MyModel()
table = widgets.TreeView()
table.set_model(model)
table[0].proxify.change_icon_size(size=20)
table.show()
# or
proxy = itemmodels.SliceFilterProxyModel(indexer=0, size=20)
proxy.set_source_model(model)
table.set_model(proxy)
table.show()

table = widgets.TreeView()
source_model = widgets.FileSystemModel()
...
table.set_model(source_model)
# table.proxifier.change_icon_size(size=(30, 30))
Image title

table = widgets.TreeView()
source_model = widgets.FileSystemModel()
...
table.set_model(source_model)
table.proxifier.change_icon_size(size=(30, 30))
Image title

Source code in prettyqt\itemmodels\proxies\slicechangeiconsizeproxymodel.py
class SliceChangeIconSizeProxyModel(itemmodels.SliceIdentityProxyModel):
    """Proxy model which changes the icon size of the Decoration role.

    Supports QColors, QPixmaps and QIcons in DecorationRole.

    ### Example

    ```py
    model = MyModel()
    table = widgets.TreeView()
    table.set_model(model)
    table[0].proxify.change_icon_size(size=20)
    table.show()
    # or
    proxy = itemmodels.SliceFilterProxyModel(indexer=0, size=20)
    proxy.set_source_model(model)
    table.set_model(proxy)
    table.show()
    ```

    === "Without proxy"

        ```py
        table = widgets.TreeView()
        source_model = widgets.FileSystemModel()
        ...
        table.set_model(source_model)
        # table.proxifier.change_icon_size(size=(30, 30))
        ```
        <figure markdown>
          ![Image title](../../images/slicechangeiconsizeproxymodel_before.png)
        </figure>

    === "With proxy"

        ```py
        table = widgets.TreeView()
        source_model = widgets.FileSystemModel()
        ...
        table.set_model(source_model)
        table.proxifier.change_icon_size(size=(30, 30))
        ```
        <figure markdown>
          ![Image title](../../images/slicechangeiconsizeproxymodel_after.png)
        </figure>

    """

    ID = "change_icon_size"
    ICON = "mdi.resize"

    def __init__(self, size: datatypes.SizeType, **kwargs):
        super().__init__(**kwargs)
        self._size = datatypes.to_size(size)
        self._cache = {}

    def data(
        self,
        index: core.ModelIndex,
        role: constants.ItemDataRole = constants.DISPLAY_ROLE,
    ):
        if role == constants.DECORATION_ROLE and self.indexer_contains(index):
            original = super().data(index, role)
            match original:
                case gui.QIcon():
                    hashed = original.cacheKey()
                    if hashed in self._cache:
                        return self._cache[hashed]
                    p = original.pixmap(self._size)
                    self._cache[hashed] = p
                    return p
                case gui.QColor():
                    hashed = original.name()
                    if hashed in self._cache:
                        return self._cache[hashed]
                    p = gui.QPixmap(self._size)
                    p.fill(original)
                    self._cache[hashed] = p
                    return p
                case gui.QPixmap():
                    hashed = original.cacheKey()
                    if hashed in self._cache:
                        return self._cache[hashed]
                    p = original.scaled(self._size)
                    self._cache[hashed] = p
                    return p
        return super().data(index, role)

    def set_icon_size(self, size: core.QSize):
        self._cache = {}
        self._size = size

    def get_icon_size(self) -> core.QSize:
        return self._size

    icon_size = core.Property(
        core.QSize,
        get_icon_size,
        set_icon_size,
        doc="New icon size",
    )

Info

This is a slice proxy and can be selectively applied to a model. Read more about slices.

⌗ Property table

Qt Property Type Doc
objectName QString
sourceModel QAbstractItemModel
column_slice QVariantList Column slice to include for the proxy
row_slice QVariantList Row slice to include for the proxy
icon_size QSize New icon size