def update_char_format(baseformat, color=None, background=None, weight=None, italic=None, underline=None, font=None): """ Return a copy of `baseformat` :class:`QTextCharFormat` with updated color, weight, background and font properties. """ charformat = QTextCharFormat(baseformat) if color is not None: charformat.setForeground(color) if background is not None: charformat.setBackground(background) if font is not None: charformat.setFont(font) else: font = update_font(baseformat.font(), weight, italic, underline) charformat.setFont(font) return charformat
def update_char_format( baseformat: QTextCharFormat, color: Optional[_Color] = None, background: Optional[_Color] = None, weight: Optional[int] = None, italic: Optional[bool] = None, underline: Optional[bool] = None, font: Optional[QFont] = None ) -> QTextCharFormat: """ Return a copy of `baseformat` :class:`QTextCharFormat` with updated color, weight, background and font properties. """ charformat = QTextCharFormat(baseformat) if color is not None: charformat.setForeground(color) if background is not None: charformat.setBackground(background) if font is not None: assert weight is None and italic is None and underline is None charformat.setFont(font) else: if weight is not None: charformat.setFontWeight(weight) if italic is not None: charformat.setFontItalic(italic) if underline is not None: charformat.setFontUnderline(underline) return charformat