Skip to content

TextCharFormatMixin

Base classes

Name Children Inherits
TextFormatMixin
prettyqt.gui.textformat

Subclasses

Class Module Description
TextCharFormat prettyqt.gui.textcharformat
TextImageFormat prettyqt.gui.textimageformat
TextTableCellFormat prettyqt.gui.texttablecellformat

⋔ Inheritance diagram

graph TD
  1473245667552["gui.TextCharFormatMixin"]
  1473245646080["gui.TextFormatMixin"]
  140713234304496["builtins.object"]
  1473245646080 --> 1473245667552
  140713234304496 --> 1473245646080

🛈 DocStrings

Bases: TextFormatMixin

Source code in prettyqt\gui\textcharformat.py
class TextCharFormatMixin(gui.TextFormatMixin):
    def __init__(
        self,
        text_color: datatypes.ColorType | gui.QBrush = None,
        bold: bool = False,
        italic: bool = False,
    ):
        super().__init__()
        if text_color is not None:
            self.set_foreground_color(text_color)
        if bold:
            self.set_font_weight("bold")
        self.setFontItalic(italic)

    def set_foreground_color(self, color: datatypes.ColorType | gui.QBrush):
        if not isinstance(color, gui.QBrush):
            color = colors.get_color(color)
        self.setForeground(color)

    def set_background_color(self, color: datatypes.ColorType | gui.QBrush):
        if not isinstance(color, gui.QBrush):
            color = colors.get_color(color)
        self.setBackground(color)

    def set_font_weight(self, weight: gui.font.WeightStr | gui.Font.Weight):
        """Set the font weight.

        Args:
            weight: font weight
        """
        self.setFontWeight(gui.font.WEIGHT.get_enum_value(weight))

    def get_font_weight(self) -> gui.font.WeightStr:
        """Get current font weight.

        Returns:
            current font weight
        """
        return gui.font.WEIGHT.inverse[self.fontWeight()]

    def set_underline_style(self, style: UnderlineStyleStr | mod.UnderlineStyle):
        """Set the underline style.

        Args:
            style: underline style
        """
        self.setUnderlineStyle(UNDERLINE_STYLE.get_enum_value(style))

    def get_underline_style(self) -> UnderlineStyleStr:
        """Get current underline style.

        Returns:
            current underline style
        """
        return UNDERLINE_STYLE.inverse[self.underlineStyle()]

    def set_vertical_alignment(
        self, alignment: VerticalAlignmentStr | gui.QTextCharFormat.VerticalAlignment
    ):
        """Set the vertical alignment.

        Args:
            alignment: vertical alignment
        """
        self.setVerticalAlignment(VERTICAL_ALIGNMENT.get_enum_value(alignment))

    def get_vertical_alignment(self) -> VerticalAlignmentStr:
        """Get current vertical alignment.

        Returns:
            current vertical alignment
        """
        return VERTICAL_ALIGNMENT.inverse[self.verticalAlignment()]

    def set_font_style_hint(self, hint: gui.font.StyleHintStr | gui.Font.StyleHint):
        """Set the font style hint.

        Args:
            hint: font style hint
        """
        self.setFontStyleHint(gui.font.STYLE_HINTS.get_enum_value(hint))

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

get_font_weight() -> gui.font.WeightStr

Get current font weight.

Source code in prettyqt\gui\textcharformat.py
def get_font_weight(self) -> gui.font.WeightStr:
    """Get current font weight.

    Returns:
        current font weight
    """
    return gui.font.WEIGHT.inverse[self.fontWeight()]

get_underline_style() -> UnderlineStyleStr

Get current underline style.

Source code in prettyqt\gui\textcharformat.py
def get_underline_style(self) -> UnderlineStyleStr:
    """Get current underline style.

    Returns:
        current underline style
    """
    return UNDERLINE_STYLE.inverse[self.underlineStyle()]

get_vertical_alignment() -> VerticalAlignmentStr

Get current vertical alignment.

Source code in prettyqt\gui\textcharformat.py
def get_vertical_alignment(self) -> VerticalAlignmentStr:
    """Get current vertical alignment.

    Returns:
        current vertical alignment
    """
    return VERTICAL_ALIGNMENT.inverse[self.verticalAlignment()]

set_font_style_hint(hint: gui.font.StyleHintStr | gui.Font.StyleHint)

Set the font style hint.

Parameters:

Name Type Description Default
hint StyleHintStr | StyleHint

font style hint

required
Source code in prettyqt\gui\textcharformat.py
def set_font_style_hint(self, hint: gui.font.StyleHintStr | gui.Font.StyleHint):
    """Set the font style hint.

    Args:
        hint: font style hint
    """
    self.setFontStyleHint(gui.font.STYLE_HINTS.get_enum_value(hint))

set_font_weight(weight: gui.font.WeightStr | gui.Font.Weight)

Set the font weight.

Parameters:

Name Type Description Default
weight WeightStr | Weight

font weight

required
Source code in prettyqt\gui\textcharformat.py
def set_font_weight(self, weight: gui.font.WeightStr | gui.Font.Weight):
    """Set the font weight.

    Args:
        weight: font weight
    """
    self.setFontWeight(gui.font.WEIGHT.get_enum_value(weight))

set_underline_style(style: UnderlineStyleStr | mod.UnderlineStyle)

Set the underline style.

Parameters:

Name Type Description Default
style UnderlineStyleStr | UnderlineStyle

underline style

required
Source code in prettyqt\gui\textcharformat.py
def set_underline_style(self, style: UnderlineStyleStr | mod.UnderlineStyle):
    """Set the underline style.

    Args:
        style: underline style
    """
    self.setUnderlineStyle(UNDERLINE_STYLE.get_enum_value(style))

set_vertical_alignment(alignment: VerticalAlignmentStr | gui.QTextCharFormat.VerticalAlignment)

Set the vertical alignment.

Parameters:

Name Type Description Default
alignment VerticalAlignmentStr | VerticalAlignment

vertical alignment

required
Source code in prettyqt\gui\textcharformat.py
def set_vertical_alignment(
    self, alignment: VerticalAlignmentStr | gui.QTextCharFormat.VerticalAlignment
):
    """Set the vertical alignment.

    Args:
        alignment: vertical alignment
    """
    self.setVerticalAlignment(VERTICAL_ALIGNMENT.get_enum_value(alignment))