Why does nothing happen when I set the palette background color on a QPushButton in some styles?

There are two different type of styles in Qt, one type just uses colors to
indicate the background, foreground etc and the other type is a pixmap based
one which usually rely on a theming engine on the underlying platform. When
the style is a pixmap based one then simply changing the palette will usually
not result in a visual change on that widget. Currently, there are three
pixmap based styles, these being Windows XP, Windows Vista and Mac.

These styles use the platform’s theming engine to draw most of the parts of
the widgets. The engine uses pixmaps to define its look. Setting the color of
a role in the Qt palette therefore will not always result in changes to the
looks of the widget, since this new color will not change the pixmap defined
in the theming engine. (Other things like font color of course will work as
usual). See:

http://qt.nokia.com/doc/qq/qq09-q-and-a.html#winxp

You have several options:

1. Go with the flow

Just accept the style. Easy, and gives your UI a consistent look.

2. Set the style of that one widget to something like Windows Style

Of course, that will make the widget look very different from all the others,
since they won’t have the same visual style (e.g. other types of borders etc).

3. Use QProxyStyle

Check out http://qt.nokia.com/doc/qproxystyle.html

4. Use Stylesheets instead

Using stylesheets will enable you to change just part of the look and feel of
a widget and still keep the native look and feel for other widgets. It will
preserve what it can about the widget being styled and enable it to be changed
easily.

See http://qt.nokia.com/doc/stylesheet.html for more information

No comments

Write a comment

Sorry, you must be logged in to post a comment.