简体   繁体   中英

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:

背景颜色是顶部和底部按钮之间的唯一区别

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):

解决方法(半透明框架位于按钮上方)

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

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);

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)

You may write your own QProxyStyle and use WinAPI functions to draw buttons with aero style and custom background color. You may look at Qt sources to see, how it done for aero. But it is very complex task.

Stylesheets are not designed to be used with any animations (like hover animation in aero).

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?

There is no standard way. If you want to use stylesheets without such unpredictable issues - you need to use "Fusion" style instead of any native styles. "Fusion" style is good base for QSS customization. See documentation

Other chance - is to use QtQuick instead of widgets.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM