View Full Version : cannot change QLCDNumber background color

11th March 2013, 14:33
here is what I do:

QPalette* palette = new QPalette();

where is the problem?

13th March 2013, 10:26
I put an LcdNummer Object in a gui. Then I used <obj>.setstylesheet...
In the stylesheet I wrote background-color: red
Works fine...

Assuming you can: final_angle-> setStylesheet(.....);

13th March 2013, 17:04
where is the problem?

QPalette* palette = new QPalette();

In the first case, this is a memory leak. You should simply retrieve the existing palette from the widget:

QPalette palette = final_angle->palette();
palette.setColor( /* whatever */ );
final_angle->setPalette( palette );

And if you read the QPalette documentation, you will see that QPalette::Background is an obsolete ColorRole. You should probably be using QPalette::Window or QPalette::Button; I don't know how painting in QLCDNumber is implemented, so I don't know which role it uses to paint its background.

You do read the documentation sometimes, don't you? Or do you just simply post a question for every problem you run into?