Skip to content

SliceAppearanceProxyModel

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
  1473290719872["itemmodels.SliceAppearanceProxyModel"]
  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 --> 1473290719872
  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

Source code in prettyqt\itemmodels\proxies\sliceappearanceproxymodel.py
class SliceAppearanceProxyModel(itemmodels.SliceIdentityProxyModel):
    ID = "slice_appearance"
    ICON = "mdi.palette-outline"

    def __init__(
        self,
        foreground: gui.QColor | gui.QBrush | str | None = None,
        background: gui.QColor | gui.QBrush | str | None = None,
        font: str | gui.QFont | None = None,
        alignment: constants.AlignmentFlag | constants.AlignmentStr | None = None,
        override: bool = True,
        **kwargs,
    ):
        super().__init__(**kwargs)
        self._foreground = gui.QColor()
        self.set_foreground(foreground)
        self._background = gui.QColor()
        self.set_background(background)
        self._font = gui.QFont()
        self.set_font(font)
        self._alignment = constants.ALIGN_CENTER_LEFT
        self.set_alignment(alignment)
        self._override = override

    def data(
        self,
        index: core.ModelIndex,
        role: constants.ItemDataRole = constants.DISPLAY_ROLE,
    ):
        data = super().data(index, role)
        if not self.indexer_contains(index):
            return data
        if self._override or data is None:
            match role:
                case constants.FOREGROUND_ROLE:
                    return self._foreground if self._foreground.isValid() else None
                case constants.BACKGROUND_ROLE:
                    return self._background if self._background.isValid() else None
                case constants.FONT_ROLE:
                    return self._font
                case constants.ALIGNMENT_ROLE:
                    return self._alignment
        return super().data(index, role)

    def set_font(self, font: gui.QFont | str | None):
        self._font = gui.QFont(font) if font else gui.QFont()
        self.update_all()

    def get_font(self) -> gui.QFont:
        return self._font or gui.QFont()

    def set_foreground(self, foreground: datatypes.ColorAndBrushType | None):
        match foreground:
            case None:
                foreground = gui.QColor()
            case gui.QBrush():
                foreground = foreground.color()
            case _:
                foreground = colors.get_color(foreground).as_qt()
        self._foreground = foreground
        self.update_all()

    def get_foreground(self) -> gui.QColor:
        return self._foreground

    def set_background(self, background: datatypes.ColorAndBrushType | None):
        match background:
            case None:
                background = gui.QColor()
            case gui.QBrush():
                background = background.color()
            case _:
                background = colors.get_color(background).as_qt()
        self._background = background
        self.update_all()

    def get_background(self) -> gui.QColor:
        return self._background

    def set_alignment(
        self, alignment: constants.AlignmentFlag | constants.AlignmentStr | None
    ):
        match alignment:
            case None:
                alignment = constants.ALIGN_CENTER_LEFT
            case str() | constants.AlignmentFlag():
                alignment = constants.ALIGNMENTS.get_enum_value(alignment)
        self._alignment = alignment
        self.update_all()

    def get_alignment(self) -> constants.AlignmentFlag:
        return self._alignment

    font_value = core.Property(
        gui.QFont,
        get_font,
        set_font,
        doc="Font to use for overriding",
    )
    foreground_value = core.Property(
        gui.QColor,
        get_foreground,
        set_foreground,
        doc="Foreground to use for overriding",
    )
    background_value = core.Property(
        gui.QColor,
        get_background,
        set_background,
        doc="Background to use for overriding",
    )
    alignment_value = core.Property(
        constants.AlignmentFlag,
        get_alignment,
        set_alignment,
        doc="Alignment to use for overriding",
    )

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
font_value QFont Font to use for overriding
foreground_value QColor Foreground to use for overriding
background_value QColor Background to use for overriding
alignment_value PySide::PyObjectWrapper Alignment to use for overriding