Skip to content

AbstractButtonMixin

Base classes

Name Children Inherits
WidgetMixin
prettyqt.widgets.widget

Subclasses

Class Module Description
AbstractButton prettyqt.widgets.abstractbutton
PushButtonMixin prettyqt.widgets.pushbutton
ToolButton prettyqt.widgets.toolbutton
RadioButton prettyqt.widgets.radiobutton
CheckBox prettyqt.widgets.checkbox

⋔ Inheritance diagram

graph TD
  1473293689216["widgets.AbstractButtonMixin"]
  1473293688240["widgets.WidgetMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473245548480["gui.PaintDeviceMixin"]
  1473293688240 --> 1473293689216
  1473299815024 --> 1473293688240
  140713234304496 --> 1473299815024
  1473245548480 --> 1473293688240
  140713234304496 --> 1473245548480

🛈 DocStrings

Bases: WidgetMixin

Abstract button widget base class, providing functionality common to buttons.

Source code in prettyqt\widgets\abstractbutton.py
class AbstractButtonMixin(widgets.WidgetMixin):
    """Abstract button widget base class, providing functionality common to buttons."""

    def __bool__(self):
        return self.isChecked()

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

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

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

    def set_style_icon(
        self,
        icon: widgets.style.StandardPixmapStr | widgets.QStyle.StandardPixmap,
        size: datatypes.SizeType = 15,
    ):
        """Set theme icon for the button.

        Args:
            icon: icon to use
            size: icon size
        """
        qicon = self.style().standardIcon(
            widgets.style.STANDARD_PIXMAP.get_enum_value(icon), None, self
        )
        self.set_icon(qicon)
        self.setIconSize(datatypes.to_size(size))

    def set_shortcut(self, shortcut: datatypes.KeySequenceType):
        self.setShortcut(datatypes.to_keysequence(shortcut))

    def get_shortcut(self) -> gui.KeySequence:
        return gui.KeySequence(
            self.shortcut().toString(), gui.KeySequence.SequenceFormat.PortableText
        )

    def setText(self, text: str):
        if not self.objectName() and widgets.app().is_debug():
            self.setObjectName(text)
        super().setText(text)

    def set_icon_size(self, size: datatypes.SizeType):
        """Set size of the icon."""
        self.setIconSize(datatypes.to_size(size))

    def get_icon_size(self) -> core.Size:
        return core.Size(self.iconSize())

    def get_value(self) -> bool:
        return self.isChecked()

    def set_value(self, value: bool):
        self.setChecked(value)

set_icon(icon: datatypes.IconType)

Set the icon for the button.

Parameters:

Name Type Description Default
icon IconType

icon to use

required
Source code in prettyqt\widgets\abstractbutton.py
def set_icon(self, icon: datatypes.IconType):
    """Set the icon for the button.

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

set_icon_size(size: datatypes.SizeType)

Set size of the icon.

Source code in prettyqt\widgets\abstractbutton.py
def set_icon_size(self, size: datatypes.SizeType):
    """Set size of the icon."""
    self.setIconSize(datatypes.to_size(size))

set_style_icon(icon: widgets.style.StandardPixmapStr | widgets.QStyle.StandardPixmap, size: datatypes.SizeType = 15)

Set theme icon for the button.

Parameters:

Name Type Description Default
icon StandardPixmapStr | StandardPixmap

icon to use

required
size SizeType

icon size

15
Source code in prettyqt\widgets\abstractbutton.py
def set_style_icon(
    self,
    icon: widgets.style.StandardPixmapStr | widgets.QStyle.StandardPixmap,
    size: datatypes.SizeType = 15,
):
    """Set theme icon for the button.

    Args:
        icon: icon to use
        size: icon size
    """
    qicon = self.style().standardIcon(
        widgets.style.STANDARD_PIXMAP.get_enum_value(icon), None, self
    )
    self.set_icon(qicon)
    self.setIconSize(datatypes.to_size(size))