So, I am making a desktop app with PyQt6. I have a stylesheet and I want it to update every time I add something to it. Stylesheet is an array and I have multiple functions adding things to it:
def set_color(self, color):
self.stylesheet.append(f"color: {color}")
def set_background_color(self, color):
self.stylesheet.append(f"background-color: {color}")
def set_border_radius(self, radius):
self.stylesheet.append(f"border-radius: {radius}px")
def set_alignment(self, alignment):
self.stylesheet.append(f"text-align: {alignment}")
Now, I want to update the stylesheet every time I call one of these functions (or a function in the class as a whole) by calling another function that updates it. But I don't want to add it manually to every function. Is there a better way of doing this?
def update_stylesheet(self):
result = ""
for css in self.stylesheet:
if css.strip():
result += css.strip()
result += "; "
self.setStyleSheet(result)