Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep Windows Aero theme after setting of background color of button in Qt?

Is there any way to change background color of widget without loosing of it's style? My problem is reproducible on Windows 7/Vista with Aero theme and on Windows 8 too. You can see how it looks in Qt Designer:

Background colour is the only difference between top and bottom buttons

Here we have four buttons: both top widgets looks good (as all other widgets of this program), but both bottom widgets looks old. The only reason of this old style is setting of background color of these buttons (as far as I understand, Desktop Window Manager resets style to old if widget is not standard).

So, is there any way to force Desktop Window Manager to draw button with not standard background color? (Microsoft Office can do it, but I am not sure it is standard feature)

Could you recommend Qt extension which replaces standard drawing of buttons by modern (Aero theme)? Or may be you know more standard way to do it?

I found only one way to change color without loosing of style: to put partially transparent widget above button (and to make it transparent for mouse clicks). You can see the result here (my frame is bigger than it is necessary - it is for demonstration; also I need color correction to compensate transparency, but it is not critical):

Workaround (semi-transparent frame is above buttons)

It works, but I don't like this "solution". Do you have better idea?

like image 484
Ilya Avatar asked Oct 20 '22 04:10

Ilya


1 Answers

I see that you are using stylesheets to modify the background colour of the buttons. I had faced the same problem a while ago. As soon as you apply a stylesheet, button looses the 3rd effect and you don't see hover effect as well. My take on it was to discard using stylesheets and use QPalette to set the colours. For example,

QPalette bluePalette(button->palette()); // original palette
bluePalette.setColor(QPalette::Button, QColor(Qt::blue)); //colour you want
button->setPalette(bluePalette);
like image 88
ramtheconqueror Avatar answered Oct 22 '22 00:10

ramtheconqueror