![]() |
Home · Overviews · Examples |
The QPalette class contains color groups for each widget state. More...
The QPalette class contains color groups for each widget state.
A palette consists of three color groups: Active, Disabled, and Inactive. All widgets in Qt contain a palette and use their palette to draw themselves. This makes the user interface easily configurable and easier to keep consistent.
If you create a new widget we strongly recommend that you use the colors in the palette rather than hard-coding specific colors.
The color groups:
Both active and inactive windows can contain disabled widgets. (Disabled widgets are often called inaccessible or grayed out.)
In most styles, Active and Inactive look the same.
Colors and brushes can be set for particular roles in any of a palette's color groups with setColor and setBrush. A color group contains a group of colors used by widgets for drawing themselves. We recommend that widgets use color group roles from the palette such as "foreground" and "base" rather than literal colors like "red" or "turquoise". The color roles are enumerated and defined in the ColorRole documentation.
We strongly recommend that you use the default palette of the current style (returned by QApplication::palette()) and modify that as necessary. This is done by Qt's widgets when they are drawn.
To modify a color group you call the functions setColor and setBrush, depending on whether you want a pure color or a pixmap pattern.
There are also corresponding color and brush getters, and a commonly used convenience function to get the ColorRole for the current ColorGroup: window, windowText, base, etc.
You can copy a palette using the copy constructor and test to see if two palettes are identical using isCopyOf.
QPalette is optimized by the use of implicit sharing, so it is very efficient to pass QPalette objects as arguments.
See also QApplication::setPalette, QWidget::setPalette, and QColor.
Copyright © 2008 Trolltech | Trademarks | Qt Jambi 4.3.5_01 |