[Interest] QWidget style change and reverting it back

Prav pr12og2 at programist.ru
Tue Feb 9 19:48:26 CET 2016


Hello, Thiago.

Thanks for explanations! But I did get clear overall picture yet.

>> I am trying to change color of QLineEdit with
>> ui->lineEdit->setStyleSheet("color: red;");
> Why didn't you just set the colour, by changing the widget's palette?
I was expecting this is the same ... but this way seemed for me to be more easy to extend ... I mean easy to edit to add more specifications
Now I get that calling setStyleSheet("color: red;") is not done via calling setPalette().


>> How  that could be that doing the same thing second time I got changed
>> size of lineEdit? ... Windows, Qt 5.5.1 ... test project is inside zip-file.
I did not get reason for this behavior. Let me explain it again.
If I press button second time I see that lineEdit changes its size? BUT ... from external point of view it looks like the same property was set to the same value again!
That second call changes something? Style? Then this mean that first call did done the job totally.
This all looks kind of magic for me ... or at least strange/unexpected behavior IMHO.



>> Or using setStyleSheet() is irreversible operation?
> It has an irreversible consequence, that of using QStyleSheetStyle for the
> widget's style, instead of whatever is the default for your platform.
I got the idea about role of QStyleSheetStyle and it make sense.

I did not get why style manipulations are made irreversible?
I was thinking that there is some king of property of widget that stores style (or style*).
How changing the value of this property could be irreversible?
Why this property can not be set to whatever it was (this is meaning of irreversible for me)?


> The QStyleSheetStyle class is supposed to mimic the
> platform's style, but it exists in the first place in order to do things that
> are not possible with the platform's style.
OK ... how one can understand which properties of style-sheet language are "possible with the platform's style" (to be able to avoid this bad-mimic behaviour of QStyleSheetStyle class as much as possible)?


> So if you use stylesheets, you *accept* that your widget will look different
> from the platform. That is not a bug. What's more, changing the style implies
> you don't want to look like the native look and feel anyway.
OK ... so QStyleSheetStyle is mimicing ... but not good ... only for now or there is no such goal to make QStyleSheetStyle look the same as app's style (QWindowsVistaStyle)?

I did not get ... are there some sort of big difficulties for QStyleSheetStyle("") to look the same as QWindowsVistaStyle?
I can imagine that QWindowsVistaStyle is not easy to implement but if implemented why it can not be used to work for other classed like QStyleSheetStyle?


> We can say there's room for improvement, though. See https://bugreports.qt.io/
> browse/QTBUG-50976 for an example.
Yes ... this is funny behavior too :)


> My personal recommendation: don't use style sheets, at all.
There is several big help-docs I read about this style-language ... but now it seems to be not recommended ... such a pity :(


>> If so how to change color of widget and then return it back.
Let me ask this question in more generous way:
How to revert the look-and-feel of widget back as it was before I start touching any look-and-feel properties of widget?




More information about the Interest mailing list