Skip to content

ProgressBarDelegate

Qt Base Class: QStyledItemDelegate

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

Base classes

Name Children Inherits
StyledItemDelegate
prettyqt.widgets.styleditemdelegate

⋔ Inheritance diagram

graph TD
  1473367030624["itemdelegates.ProgressBarDelegate"]
  1473296354464["widgets.StyledItemDelegate"]
  1473296344704["widgets.AbstractItemDelegateMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473293727280["QtWidgets.QStyledItemDelegate"]
  1473293758512["QtWidgets.QAbstractItemDelegate"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473296354464 --> 1473367030624
  1473296344704 --> 1473296354464
  1473299815024 --> 1473296344704
  140713234304496 --> 1473299815024
  1473293727280 --> 1473296354464
  1473293758512 --> 1473293727280
  1473288842240 --> 1473293758512
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208

🛈 DocStrings

Bases: StyledItemDelegate

Delegate to show a value in form of a progress bar.

Source code in prettyqt\itemdelegates\progressbardelegate.py
class ProgressBarDelegate(widgets.StyledItemDelegate):
    """Delegate to show a value in form of a progress bar."""

    ID = "progress_bar"

    def __init__(
        self,
        role: constants.ItemDataRole = constants.DISPLAY_ROLE,
        total: int = 100,
        **kwargs,
    ):
        self._role = role
        self._total = total
        super().__init__(**kwargs)

    def paint(
        self,
        painter: gui.QPainter,
        option: widgets.QStyleOptionViewItem,
        index: core.ModelIndex,
    ):
        progress = index.data(self._role)
        opt = widgets.StyleOptionProgressBar()
        opt.rect = option.rect
        opt.minimum = 0
        opt.maximum = self._total
        opt.progress = progress
        opt.text = f"{progress}%"
        opt.textVisible = True
        opt.state |= widgets.Style.StateFlag.State_Horizontal
        widgets.Application.style().drawControl(
            widgets.Style.ControlElement.CE_ProgressBar, opt, painter
        )

    def set_total(self, total: int):
        self._total = total

    def get_total(self) -> int:
        return self._total

    def set_role(self, role: constants.ItemDataRole):
        self._role = role

    def get_role(self) -> constants.ItemDataRole:
        return self._role

    total = core.Property(
        int,
        get_total,
        set_total,
        doc="Total value for the progress bar",
    )
    role = core.Property(
        constants.ItemDataRole,
        get_role,
        set_role,
        doc="Role to use for the progress bar value",
    )

⌗ Property table

Qt Property Type Doc
objectName QString
total int Total value for the progress bar
role PySide::PyObjectWrapper Role to use for the progress bar value

Delegate ID: progress_bar