Skip to content

LayoutHierarchyModel

Qt Base Class: QAbstractItemModel

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

Base classes

Name Children Inherits
BaseHierarchyModel
prettyqt.itemmodels.widgethierarchymodel

⋔ Inheritance diagram

graph TD
  1473290711088["itemmodels.LayoutHierarchyModel"]
  1473290713040["itemmodels.BaseHierarchyModel"]
  1473299686192["itemmodels.TreeModel"]
  1473299893104["core.AbstractItemModel"]
  1473299890176["core.AbstractItemModelMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473289050128["QtCore.QAbstractItemModel"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473290713040 --> 1473290711088
  1473299686192 --> 1473290713040
  1473299893104 --> 1473299686192
  1473299890176 --> 1473299893104
  1473299815024 --> 1473299890176
  140713234304496 --> 1473299815024
  1473289050128 --> 1473299893104
  1473288842240 --> 1473289050128
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208

🛈 DocStrings

Bases: BaseHierarchyModel

Tree model showing the layout hierarchy of widgets.

Source code in prettyqt\itemmodels\widgethierarchymodel.py
class LayoutHierarchyModel(BaseHierarchyModel):
    """Tree model showing the layout hierarchy of widgets."""

    SUPPORTS = "widgets.QWidget"

    @classmethod
    def supports(cls, instance) -> bool:
        from prettyqt import widgets

        return isinstance(instance, widgets.QWidget)

    def _fetch_object_children(
        self, item: LayoutHierarchyModel.TreeItem
    ) -> list[LayoutHierarchyModel.TreeItem]:
        from prettyqt import widgets

        match item.obj:
            case (
                widgets.QSplitter()
                | widgets.QToolBox()
                | widgets.QStackedWidget()
                | widgets.QTabWidget()
            ):
                items = [item.obj.widget(i) for i in range(item.obj.count())]
            case widgets.QWidget():
                layout = item.obj.layout()
                items = [layout.itemAt(i) for i in range(layout.count())]
                items = [w if (w := i.widget()) else i.layout() for i in items]
            case widgets.QLayout():
                layout = item.obj
                items = [layout.itemAt(i) for i in range(layout.count())]
                items = [w if (w := i.widget()) else i.layout() for i in items]
            case _:
                raise ValueError(item)
        return [self.TreeItem(obj=i) for i in items]

    def _has_children(self, item: LayoutHierarchyModel.TreeItem) -> bool:
        from prettyqt import widgets

        match item.obj:
            case (
                widgets.QSplitter()
                | widgets.QToolBox()
                | widgets.QStackedWidget()
                | widgets.QTabWidget()
                | widgets.QLayout()
            ):
                return item.obj.count() > 0
            case _:
                layout = item.obj.layout()
                return False if layout is None else layout.count() > 0

Info

Supported data type: widgets.QWidget

⌗ Property table

Qt Property Type Doc
objectName QString
base_class_name QString Class to use for the columns.