Add a function to convert QColor to CSS rgba format

This commit is contained in:
Veronica Berglyd Olsen
2024-03-27 13:11:37 +01:00
parent 3e66968387
commit 2d9b57b534
6 changed files with 67 additions and 62 deletions
+6 -1
View File
@@ -36,7 +36,7 @@ from configparser import ConfigParser
from urllib.parse import urljoin
from urllib.request import pathname2url
from PyQt5.QtGui import QDesktopServices
from PyQt5.QtGui import QColor, QDesktopServices
from PyQt5.QtCore import QCoreApplication, QUrl
from novelwriter.enum import nwItemClass, nwItemType, nwItemLayout
@@ -382,6 +382,11 @@ def numberToRoman(value: int, toLower: bool = False) -> str:
return roman.lower() if toLower else roman
def cssCol(col: QColor, alpha: int | None = None) -> str:
"""Convert a QColor object to an rgba entry to use in CSS."""
return f"rgba({col.red()}, {col.green()}, {col.blue()}, {alpha or col.alpha()})"
##
# Encoder Functions
##