View Full Version : cannot change QLCDNumber background color
saman_artorious
11th March 2013, 14:33
here is what I do:
final_angle->display(44.4);
QPalette* palette = new QPalette();
palette->setColor(QPalette::Background,Qt::red);
final_angle->setPalette(*palette);
where is the problem?
m3rlin
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(.....);
d_stranz
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?
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.