I have the animated button. This is how I create animation:
self._animation = QtCore.QVariantAnimation(
startValue=QtGui.QColor(self.color_light_orange),
endValue=QtGui.QColor(self.color_dark_orange),
valueChanged=self._on_value_changed,
duration=150,
)
def _on_value_changed(self, color):
self._update_stylesheet(color)
def _update_stylesheet(self, background):
self.setStyleSheet(#stylesheet)
The thing is everytime button hovered _update_stylesheet
function called. As you can see it has background
argument which is desired background to set. I know I could insert all stylesheet like this:
self.setStyleSheet(f"""
...
background-color: {background}
...
""")
But stylesheet for this button is about 20 lines and I would like to place it inside separate style.css file. The problem is that I don't know how to change only background so I could do like this:
# Set css file for the whole app
with open("style.css", "r") as f:
app.setSheetStyle(f.read())
...
def _update_stylesheet(self, background):
self.changeOnlyOneAttribute(background) # Function I would like to have
If there are another ideas to keep stylesheet separatly inside style.css tell me please!