27 lines
914 B
Python
27 lines
914 B
Python
from dataclasses import dataclass, field
|
|
from PySide6 import QtWidgets, QtGui, QtCore
|
|
|
|
@dataclass
|
|
class TextFormat:
|
|
font_family: str = "Segoe UI"
|
|
font_size: str = "10"
|
|
bold: bool = False
|
|
italic: bool = False
|
|
underline: bool = False
|
|
fg_color: tuple[int] = field(default=(0,0,0))
|
|
format: QtGui.QTextCharFormat = field(default_factory=QtGui.QTextCharFormat, init=False, repr=False)
|
|
|
|
def __post_init__(self):
|
|
format = QtGui.QTextCharFormat()
|
|
format.setFontFamily(self.font_family)
|
|
format.setFontPointSize(int(self.font_size))
|
|
format.setForeground(QtGui.QColor(*self.fg_color))
|
|
if self.bold:
|
|
format.setFontWeight(QtGui.QFont.Bold)
|
|
if self.italic:
|
|
format.setFontItalic(True)
|
|
if self.underline:
|
|
format.setUnderlineStyle(QtGui.QTextCharFormat.SingleUnderline)
|
|
|
|
self.format = format
|