PDA

View Full Version : stylesheet change on changing object name



moh.gup@gmail.com
30th June 2012, 06:45
Hi,
I applied style sheet on widget with different object name.I m changing object name of widget at run time,but stylesheet corresponding to new object name doesnot reflect on widget.I also tried update(),but no use

Please suggest

ChrisW67
30th June 2012, 06:59
I suggest you provide some actual information on what you have done, what you expected to see, and what you actually saw. All we know is that you applied style sheet to a widget.

moh.gup@gmail.com
30th June 2012, 07:53
Hi,
I attached a sample program in which i m try to change stylesheet of widget by changing object name on clicking the button.

Please see the code and let me know where am i woring

Thanks

wysota
30th June 2012, 08:00
Stylesheets are not reevaluated when properties of widgets change. The only way to force reevaluation is to reapply the stylesheet. However changing object names in the middle of the program is probably not a good thing to do in general.

moh.gup@gmail.com
30th June 2012, 08:09
I have constraint to apply stylesheet only once in my project. Can u suggest other good and proper way to solve my problem.

wysota
30th June 2012, 08:13
I have constraint to apply stylesheet only once in my project. Can u suggest other good and proper way to solve my problem.

Don't use stylesheets.

moh.gup@gmail.com
30th June 2012, 08:19
Please suggest any alternative?

Charvi
30th June 2012, 08:21
Yes. Do it from your program. Apply the effects first then when the desired button is clicked, override its click event and in that change the effects of the widget again.

This way you will even not need to change the object name of the widget from inside the program.

wysota
30th June 2012, 08:55
Please suggest any alternative?

I don't know what you are trying to do so it is hard to suggest an alternative. Subclassing QStyle is a likely solution however changing an object property will still not trigger a redraw automatically. If you are using stylesheets then reapplying the stylesheet seems the best option.

alxsabo
3rd July 2012, 19:10
Hi,
I applied style sheet on widget with different object name.I m changing object name of widget at run time,but stylesheet corresponding to new object name doesnot reflect on widget.I also tried update(),but no use

Please suggest

after changing object name just call setStyleSheet("")


label->setObjectName("errorLabel");
label->setStyleSheet("");

this will update stylesheet for this widget :)