Trying to save the stylesheet options of an object after a new one has been created
-
Hi. I have an object (which is tied to a ui file) and a function that changes the stylesheet of said object such that the text would be in red. This object will be closed regularly and I would like to be able to save the modified stylesheet such that the text would remain red after I reopen the stylesheet. My stylesheet is defined in the ui file, and not the cpp file.
The immediate method I can think of to "save" said stylesheet would be to create another object (maybe a QString that saves 'red', 'blue', 'black') and have it act as an input to the color changer function, then run the color changer everytime this object is created. However, I was wondering whether there is a simple way I could modify and save this new stylesheet such that I don't have to run this color changing function everytime I create the object.
Please let me know if more information is required.
-
Hi. I have an object (which is tied to a ui file) and a function that changes the stylesheet of said object such that the text would be in red. This object will be closed regularly and I would like to be able to save the modified stylesheet such that the text would remain red after I reopen the stylesheet. My stylesheet is defined in the ui file, and not the cpp file.
The immediate method I can think of to "save" said stylesheet would be to create another object (maybe a QString that saves 'red', 'blue', 'black') and have it act as an input to the color changer function, then run the color changer everytime this object is created. However, I was wondering whether there is a simple way I could modify and save this new stylesheet such that I don't have to run this color changing function everytime I create the object.
Please let me know if more information is required.
@Dummie1138
You will indeed to save it yourself, the code generated (viauic) from your.uifile is for as it was when you designed it and hence will not contain the modification the next time you run the Qt program.Save the current
widget->styleSheet()string, or whatever information you want to be able to redo what you need to do. You might save it to settings viaQSettings. When your program starts, look for this saved value and if found apply to your widget during startup. -
Hi,
Shouldn't the change of color rather depend on the state of the widget ? You can use a dynamic property.
Doing so you will need only one stylesheet without the need to change it yourself.