Skip to content

ListViewGridResizeEventFilter

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
  1473367048192["eventfilters.ListViewGridResizeEventFilter"]
  1473367044288["eventfilters.BaseEventFilter"]
  1473299782816["core.Object"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473367044288 --> 1473367048192
  1473299782816 --> 1473367044288
  1473299815024 --> 1473299782816
  140713234304496 --> 1473299815024
  1473288842240 --> 1473299782816
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208

🛈 DocStrings

Bases: BaseEventFilter

Eventfilter that scales grid size of ListViews.

Source code in prettyqt\eventfilters\listviewgridresizeeventfilter.py
class ListViewGridResizeEventFilter(eventfilters.BaseEventFilter):
    """Eventfilter that scales grid size of ListViews."""

    ID = "listview_grid_resize"

    def __init__(
        self, num_columns: int = 5, parent: widgets.ListView | None = None, **kwargs
    ):
        super().__init__(parent=parent, **kwargs)
        self._view_columns = num_columns

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

    def _resize(self, source: widgets.ListView):
        width = source.width() - 30
        # The minus 30 above ensures we don't end up with an item width that
        # can't be drawn the expected number of times across the view without
        # being wrapped. Without this, the view can flicker during resize
        tile_width = int(width / self._view_columns)
        icon_width = int(tile_width * 0.8)
        source.setGridSize(core.QSize(tile_width, tile_width))
        source.setIconSize(core.QSize(icon_width, icon_width))

⌗ Property table

Qt Property Type Doc
objectName QString