|
| QPalette () |
|
| QPalette (const QBrush &windowText, const QBrush &button, const QBrush &light, const QBrush &dark, const QBrush &mid, const QBrush &text, const QBrush &bright_text, const QBrush &base, const QBrush &window) |
|
| QPalette (const QColor &button) |
|
| QPalette (const QColor &button, const QColor &window) |
|
| QPalette (const QColor &windowText, const QColor &window, const QColor &light, const QColor &dark, const QColor &mid, const QColor &text, const QColor &base) |
|
| QPalette (const QPalette &other) |
|
| QPalette (QPalette &&other) |
|
| QPalette (Qt::GlobalColor button) |
|
| ~QPalette () |
|
const QBrush & | alternateBase () const |
|
const QBrush & | background () const |
|
const QBrush & | base () const |
|
const QBrush & | brightText () const |
|
const QBrush & | brush (ColorGroup group, ColorRole role) const |
|
const QBrush & | brush (ColorRole role) const |
|
const QBrush & | button () const |
|
const QBrush & | buttonText () const |
|
qint64 | cacheKey () const |
|
const QColor & | color (ColorGroup group, ColorRole role) const |
|
const QColor & | color (ColorRole role) const |
|
ColorGroup | currentColorGroup () const |
|
const QBrush & | dark () const |
|
const QBrush & | foreground () const |
|
const QBrush & | highlight () const |
|
const QBrush & | highlightedText () const |
|
bool | isBrushSet (ColorGroup group, ColorRole role) const |
|
bool | isCopyOf (const QPalette &other) const |
|
bool | isEqual (ColorGroup group1, ColorGroup group2) const |
|
const QBrush & | light () const |
|
const QBrush & | link () const |
|
const QBrush & | linkVisited () const |
|
const QBrush & | mid () const |
|
const QBrush & | midlight () const |
|
| operator QVariant () const |
|
bool | operator!= (const QPalette &other) const |
|
QPalette & | operator= (const QPalette &other) |
|
QPalette & | operator= (QPalette &&other) |
|
bool | operator== (const QPalette &other) const |
|
QPalette | resolve (const QPalette &other) const |
|
void | setBrush (ColorGroup group, ColorRole role, const QBrush &brush) |
|
void | setBrush (ColorRole role, const QBrush &brush) |
|
void | setColor (ColorGroup group, ColorRole role, const QColor &color) |
|
void | setColor (ColorRole role, const QColor &color) |
|
void | setColorGroup (ColorGroup group, const QBrush &windowText, const QBrush &button, const QBrush &light, const QBrush &dark, const QBrush &mid, const QBrush &text, const QBrush &bright_text, const QBrush &base, const QBrush &window) |
|
void | setCurrentColorGroup (ColorGroup group) |
|
const QBrush & | shadow () const |
|
void | swap (QPalette &other) |
|
const QBrush & | text () const |
|
const QBrush & | toolTipBase () const |
|
const QBrush & | toolTipText () const |
|
const QBrush & | window () const |
|
const QBrush & | windowText () const |
|
The QPalette class contains color groups for each widget state. All widgets contain a palette and use their palette to draw themselves. When creating a new widget class we strongly recommend using the colors in the palette rather than hard coding specific colors.
The available color groups are listed below.
- Active group
- For the window that has keyboard focus
- Inactive group
- For windows which are enabled but do not have focus
- Disabled group
- For widgets (not windows) that are disabled for some reason
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 using the default palette of the current style, returned by QApplication::palette(), and modify that as necessary.
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.
- Warning
- Some styles do not use the palette for all drawing. This occurs when the style uses a native theme engine. This is the case for Windows XP, Windows Vista, and the Mac OS X styles.
- See also
- QApplication::setPalette(), QWidget::setPalette(), QColor
The ColorRole enum defines the different symbolic color roles used in current GUIs.
The central roles are:
Constant | Value | Description |
QPalette::Window | 10 | A general background color. |
QPalette::Background | Window | This value is obsolete. Use Window instead. |
QPalette::WindowText | 0 | A general foreground color. |
QPalette::Foreground | WindowText | This value is obsolete. Use WindowText instead. |
QPalette::Base | 9 | Used mostly as the background color for text entry widgets, but can also be used for other painting - such as the background of combobox drop down lists and toolbar handles. It is usually white or another light color. |
QPalette::AlternateBase | 16 | Used as the alternate background color in views with alternating row colors (refer to QAbstractItemView::setAlternatingRowColors()). |
QPalette::ToolTipBase | 18 | Used as the background color for QToolTip and QWhatsThis. Tool tips use the Inactive color group of QPalette, because tool tips are not active windows. |
QPalette::ToolTipText | 19 | Used as the foreground color for QToolTip and QWhatsThis. Tool tips use the Inactive color group of QPalette, because tool tips are not active windows. |
QPalette::Text | 6 | The foreground color used with Base . This is usually the same as the WindowText , in which case it must provide good contrast with Window and Base . |
QPalette::Button | 1 | The general button background color. This background can be different from Window as some styles require a different background color for buttons. |
QPalette::ButtonText | 8 | A foreground color used with the Button color. |
QPalette::BrightText | 7 | A text color that is very different from WindowText , and contrasts well with e.g. Dark . Typically used for text which needs to be drawn where Text or WindowText would give poor contrast, such as on pressed push buttons. Text colors can be used for more than just words. For example, lines and icons |
There are some color roles used mostly for 3D bevel and shadow effects. All of these are normally derived from Window
, and used in ways that depend on that relationship. For example, buttons depend on it to make the bevels look attractive.
Constant | Value | Description |
QPalette::Light | 2 | Lighter than Button color |
QPalette::Midlight | 3 | Between Button and Light |
QPalette::Dark | 4 | Darker than Button |
QPalette::Mid | 5 | Between Button and Dark |
QPalette::Shadow | 11 | A very dark color, by default the shadow color is Qt::black |
QPalette::Highlight | 12 | A color to indicate a selected item or the current item, by default the highlight color is Qt::darkBlue |
QPalette::HighlightedText | 13 | A text color which contrasts with Highlight , by default the highlighted text color is Qt::white |
QPalette::Link | 14 | A text color used for unvisited hyperlinks, by default the link color is Qt::blue |
QPalette::LinkVisited | 15 | A text color used for already visited hyperlinks, by default the linkvisited color is Qt::magenta |
QPalette::NoRole | 17 | No role, this special role is often used to indicate a role has not been assigned |
Rules 12 and 13 apply to selected (marked) items. Rules 14 and 15 are related to hyperlinks.
Do not use the Link
and LinkVisited
roles when rendering rich text in CopperSpice. Use CSS and the QTextDocument::setDefaultStyleSheet() function to alter the appearance of links.
QString sheet = QString::fromLatin1(
"a { text-decoration: underline; color: %1 }").formatArg(linkColor.name());
browser.
document()->setDefaultStyleSheet(sheet);