Skip to content

SectionAutoSpanEventFilter

Qt Base Class: QObject

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

Base classes

Name Children Inherits
BaseEventFilter
prettyqt.eventfilters.baseeventfilter

⋔ Inheritance diagram

graph TD
  1473367058928["eventfilters.SectionAutoSpanEventFilter"]
  1473367044288["eventfilters.BaseEventFilter"]
  1473299782816["core.Object"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473367044288 --> 1473367058928
  1473299782816 --> 1473367044288
  1473299815024 --> 1473299782816
  140713234304496 --> 1473299815024
  1473288842240 --> 1473299782816
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208

🛈 DocStrings

Bases: BaseEventFilter

Source code in prettyqt\eventfilters\sectionautospaneventfilter.py
class SectionAutoSpanEventFilter(eventfilters.BaseEventFilter):
    ID = "autospan_sections"

    def __init__(
        self,
        parent: widgets.TableView | widgets.TreeView,
        orientation: constants.Orientation
        | constants.OrientationStr = constants.HORIZONTAL,
    ):
        super().__init__(parent)
        self._widget = parent
        self._last_start = None
        self._last_end = None
        self.orientation = constants.ORIENTATION.get_enum_value(orientation)
        if self.orientation == constants.HORIZONTAL:
            parent.h_scrollbar.valueChanged.connect(self._update_spans)
        else:
            parent.v_scrollbar.valueChanged.connect(self._update_spans)
        parent.model().headerDataChanged.connect(self._on_force_update)
        parent.model_changed.connect(self._on_force_update)
        parent.installEventFilter(self)
        self._update_spans()
        # sel_model = parent.selectionModel()
        # if not sel_model:
        #     return

    def _on_force_update(self):
        self._update_spans(True)

    def eventFilter(self, obj, event: core.Event) -> bool:
        match event.type():
            case core.Event.Type.Resize:
                self._update_spans()
                return False
        return super().eventFilter(obj, event)

    def _update_spans(self, force: bool = False):
        cols = self._widget.get_visible_section_span("horizontal", margin=1)
        rows = self._widget.get_visible_section_span("vertical", margin=1)
        start = (rows[0], cols[0])
        end = (rows[1], cols[1])
        if start == self._last_start and end == self._last_end and not force:
            return
        self._last_start = start
        self._last_end = end
        self._widget.clearSpans()
        self._widget.auto_span(orientation=self.orientation, start=start, end=end)

⌗ Property table

Qt Property Type Doc
objectName QString