Skip to content

ListWidgetItem

Base classes

Name Children Inherits
SerializeMixin
prettyqt.utils.serializemixin
QListWidgetItem
PySide6.QtWidgets
QListWidgetItem(self, text: str, /, listview: PySide6.QtWidgets.QListWidget | None \= None, type: int \= <ItemType.Type: 0>) -> None

â‹” Inheritance diagram

graph TD
  3130383506["widgets.ListWidgetItem"]
  69336483["utils.SerializeMixin"]
  2751680898["builtins.object"]
  2691890077["QtWidgets.QListWidgetItem"]
  37984305["Shiboken.Object"]
  69336483 --> 3130383506
  2751680898 --> 69336483
  2691890077 --> 3130383506
  37984305 --> 2691890077
  2751680898 --> 37984305

🛈 DocStrings

Bases: SerializeMixin, QListWidgetItem

Item for use with the QListWidget item view class.

Source code in prettyqt/widgets/listwidgetitem.py
class ListWidgetItem(serializemixin.SerializeMixin, QtWidgets.QListWidgetItem):
    """Item for use with the QListWidget item view class."""

    def __repr__(self):
        return get_repr(self, self.icon(), self.text())

    def __setitem__(self, index: int | constants.ItemDataRoleStr, value):
        self.set_data(index, value)

    def __getitem__(self, index: int | constants.ItemDataRoleStr):
        return self.get_data(index)

    def set_icon(self, icon: datatypes.IconType):
        """Set the icon for the action.

        Args:
            icon: icon to use
        """
        icon = iconprovider.get_icon(icon)
        self.setIcon(icon)

    def set_checkstate(self, state: constants.CheckStateStr | constants.CheckState):
        """Set checkstate of the checkbox.

        Args:
            state: checkstate to use
        """
        self.setCheckState(constants.CHECK_STATE.get_enum_value(state))

    def get_checkstate(self) -> constants.CheckStateStr:
        """Return checkstate.

        Returns:
            checkstate
        """
        return constants.CHECK_STATE.inverse[self.checkState()]

    def get_background(self) -> gui.Brush:
        return gui.Brush(self.background())

    def get_foreground(self) -> gui.Brush:
        return gui.Brush(self.foreground())

    def get_font(self) -> gui.Font:
        return gui.Font(self.font())

    def get_icon(self) -> gui.Icon | None:
        return None if (icon := super().icon()).isNull() else gui.Icon(icon)

    def set_data(self, role: constants.ItemDataRoleStr | int, data: Any):
        role = constants.ITEM_DATA_ROLE[role] if isinstance(role, str) else role
        super().setData(role, data)

    def get_data(self, role: constants.ItemDataRoleStr | int):
        role = constants.ITEM_DATA_ROLE[role] if isinstance(role, str) else role
        return super().data(role)

    def set_size_hint(self, hint: datatypes.SizeType):
        super().setSizeHint(datatypes.to_size(hint))

    def set_text_alignment(
        self,
        horizontal: constants.HorizontalAlignmentStr
        | constants.AlignmentFlag
        | None = None,
        vertical: constants.VerticalAlignmentStr | constants.AlignmentFlag | None = None,
    ):
        """Set text alignment of the checkbox.

        Args:
            horizontal: horizontal text alignment to use
            vertical: vertical text alignment to use

        """
        if horizontal is None and vertical is None:
            return
        flag = constants.AlignmentFlag(0)
        if vertical is not None:
            flag |= constants.V_ALIGNMENT.get_enum_value(vertical)
        if horizontal is not None:
            flag |= constants.H_ALIGNMENT.get_enum_value(horizontal)
        self.setTextAlignment(flag)

get_checkstate() -> constants.CheckStateStr

Return checkstate.

Source code in prettyqt/widgets/listwidgetitem.py
def get_checkstate(self) -> constants.CheckStateStr:
    """Return checkstate.

    Returns:
        checkstate
    """
    return constants.CHECK_STATE.inverse[self.checkState()]

set_checkstate(state: constants.CheckStateStr | constants.CheckState)

Set checkstate of the checkbox.

Parameters:

Name Type Description Default
state CheckStateStr | CheckState

checkstate to use

required
Source code in prettyqt/widgets/listwidgetitem.py
def set_checkstate(self, state: constants.CheckStateStr | constants.CheckState):
    """Set checkstate of the checkbox.

    Args:
        state: checkstate to use
    """
    self.setCheckState(constants.CHECK_STATE.get_enum_value(state))

set_icon(icon: datatypes.IconType)

Set the icon for the action.

Parameters:

Name Type Description Default
icon IconType

icon to use

required
Source code in prettyqt/widgets/listwidgetitem.py
def set_icon(self, icon: datatypes.IconType):
    """Set the icon for the action.

    Args:
        icon: icon to use
    """
    icon = iconprovider.get_icon(icon)
    self.setIcon(icon)

set_text_alignment(horizontal: constants.HorizontalAlignmentStr | constants.AlignmentFlag | None = None, vertical: constants.VerticalAlignmentStr | constants.AlignmentFlag | None = None)

Set text alignment of the checkbox.

Parameters:

Name Type Description Default
horizontal HorizontalAlignmentStr | AlignmentFlag | None

horizontal text alignment to use

None
vertical VerticalAlignmentStr | AlignmentFlag | None

vertical text alignment to use

None
Source code in prettyqt/widgets/listwidgetitem.py
def set_text_alignment(
    self,
    horizontal: constants.HorizontalAlignmentStr
    | constants.AlignmentFlag
    | None = None,
    vertical: constants.VerticalAlignmentStr | constants.AlignmentFlag | None = None,
):
    """Set text alignment of the checkbox.

    Args:
        horizontal: horizontal text alignment to use
        vertical: vertical text alignment to use

    """
    if horizontal is None and vertical is None:
        return
    flag = constants.AlignmentFlag(0)
    if vertical is not None:
        flag |= constants.V_ALIGNMENT.get_enum_value(vertical)
    if horizontal is not None:
        flag |= constants.H_ALIGNMENT.get_enum_value(horizontal)
    self.setTextAlignment(flag)

:fa-brands-github: Show source on GitHub