import re from PySide6.QtGui import QColor def is_hex_color(color: str): return re.match("[0-9a-f]{6}", color, flags=re.IGNORECASE) def is_hex_color_with_alpha(color: str): return re.match("[0-9a-f]{8}", color, flags=re.IGNORECASE) def to_qcolor(color: str): if is_hex_color(color): red = int(color[0:2], 16) green = int(color[2:4], 16) blue = int(color[4:6], 16) return QColor(red, green, blue) if is_hex_color_with_alpha(color): red = int(color[0:2], 16) green = int(color[2:4], 16) blue = int(color[4:6], 16) alpha = int(color[6:8], 16) return QColor(red, green, blue, alpha) elif color in QColor().colorNames(): return QColor(color) return QColor(255, 255, 255)