Skip to content

SubClassTreeModel

Qt Base Class: QAbstractItemModel

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

Base classes

Name Children Inherits
BaseClassTreeModel
prettyqt.itemmodels.classtreemodel

⋔ Inheritance diagram

graph TD
  1473245425504["itemmodels.SubClassTreeModel"]
  1473245438192["itemmodels.BaseClassTreeModel"]
  1473299686192["itemmodels.TreeModel"]
  1473299893104["core.AbstractItemModel"]
  1473299890176["core.AbstractItemModelMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473289050128["QtCore.QAbstractItemModel"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473245438192 --> 1473245425504
  1473299686192 --> 1473245438192
  1473299893104 --> 1473299686192
  1473299890176 --> 1473299893104
  1473299815024 --> 1473299890176
  140713234304496 --> 1473299815024
  1473289050128 --> 1473299893104
  1473288842240 --> 1473289050128
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208

🛈 DocStrings

Bases: BaseClassTreeModel

Model to display the subclass tree of a python class.

from prettyqt import itemmodels, widgets

app = widgets.app()
widget = widgets.TreeView()
model = itemmodels.SubClassTreeModel(core.AbstractItemModelMixin)
widget.set_model(model)
widget.show()

Image title

Source code in prettyqt\itemmodels\classtreemodel.py
class SubClassTreeModel(BaseClassTreeModel):
    """Model to display the subclass tree of a python class.

    ```py
    from prettyqt import itemmodels, widgets

    app = widgets.app()
    widget = widgets.TreeView()
    model = itemmodels.SubClassTreeModel(core.AbstractItemModelMixin)
    widget.set_model(model)
    widget.show()
    ```

    <figure markdown>
      ![Image title](abstractitemmodelmixin_subclasses.png)
    </figure>
    """

    SUPPORTS = type | types.UnionType

    @classmethod
    def supports(cls, instance) -> bool:
        return isinstance(instance, type | types.UnionType)

    def _fetch_object_children(
        self, item: SubClassTreeModel.TreeItem
    ) -> list[SubClassTreeModel.TreeItem]:
        if isinstance(item.obj, types.UnionType):
            return [self.TreeItem(obj=i) for i in get_args(item.obj)]
        return [self.TreeItem(obj=i) for i in item.obj.__subclasses__()]

    def _has_children(self, item: SubClassTreeModel.TreeItem) -> bool:
        if item.obj is None:
            return False
        if isinstance(item.obj, types.UnionType):
            return True
        return len(item.obj.__subclasses__()) > 0

Info

Supported data type: type | types.UnionType

⌗ Property table

Qt Property Type Doc
objectName QString