PDA

View Full Version : QButton color changing in Qt 4.8 on Raspberry



TommyB90
24th August 2016, 16:39
Hi to everyone,
I have an issue with changing the color of a QPushButton. I have to change the color, of a pushbutton to green in certain conditions.

I got the code working on Qt 4.8.6 on a Debian machine, but the same code (listed below) doesn't behave at the same manner on a Raspberry Pi.

QPalette PHighlighted = palette();
PHighlighted.setColor(QPalette::Button, QColor(Qt::green));
ui->Btn->setPalette(PHighlighted);

In the first case all the button becomes green with a black text, but on the Raspberry only a small frame around the edges of the button changes to green (with small to none visible effect).

Any ideas?
Thanks in advance

P.S. I use Qt 4.8.6 with QtCreator 3.2.1 if it is helpful.

anda_skoa
24th August 2016, 18:04
Could be that the style on the RPi is using a different color role or you need to setAutoFillBackground(true) on the button.

Cheers,
_

TommyB90
25th August 2016, 19:33
Thanks for the fast reply!

I tried inserting the line

ui->Btn->setAutoFillBackground(true);

at the class initialization and before each palette change that I had to make, but with no result. I also tried with using the Role option with all Active, Inactive and Disabled.
The state of things didn't change: when the palette change is requested, only the frame changes its color.

I checked at this point if it could be a library issue and updated the existing ones. I do not get a library error message during execution, so I assumed that no graphic library is missing.

Thanks again a lot!

anda_skoa
26th August 2016, 00:11
You could try starting with a different widget style, so check if the style does things differently.

E.g.
application -style windows

Cheers,
_

TommyB90
26th August 2016, 09:25
I just tried your solution.

It seems to be working as the button now turns green when I want.
The problem with this is that the shape of all the widget is changed and doesn't have rounded angles anymore.
12097
12098
I will keep this as a temporary solution as it is working, but will try also with other ways.

Thanks for all the help!

anda_skoa
26th August 2016, 13:09
You could check which style is normally loaded and try a different style.

You could also try setting a style sheet instead of the palette or using a proxy style to draw just the button differently.

Cheers,
_