CopperSpice API  1.9.1
QPalette Class Reference

Contains color groups for each widget state. More...

Public Types

enum  ColorGroup
 
enum  ColorRole
 

Public Methods

 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 QBrushalternateBase () const
 
const QBrushbackground () const
 
const QBrushbase () const
 
const QBrushbrightText () const
 
const QBrushbrush (ColorGroup group, ColorRole role) const
 
const QBrushbrush (ColorRole role) const
 
const QBrushbutton () const
 
const QBrushbuttonText () const
 
qint64 cacheKey () const
 
const QColorcolor (ColorGroup group, ColorRole role) const
 
const QColorcolor (ColorRole role) const
 
ColorGroup currentColorGroup () const
 
const QBrushdark () const
 
const QBrushforeground () const
 
const QBrushhighlight () const
 
const QBrushhighlightedText () const
 
bool isBrushSet (ColorGroup group, ColorRole role) const
 
bool isCopyOf (const QPalette &other) const
 
bool isEqual (ColorGroup group1, ColorGroup group2) const
 
const QBrushlight () const
 
const QBrushlink () const
 
const QBrushlinkVisited () const
 
const QBrushmid () const
 
const QBrushmidlight () 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 QBrushshadow () const
 
void swap (QPalette &other)
 
const QBrushtext () const
 
const QBrushtoolTipBase () const
 
const QBrushtoolTipText () const
 
const QBrushwindow () const
 
const QBrushwindowText () const
 

Friends

QDataStreamoperator<< (QDataStream &stream, const QPalette &palette)
 

Related Functions

These are not member functions

QDataStreamoperator>> (QDataStream &stream, QPalette &palette)
 

Detailed Description

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

Member Enumeration Documentation

ConstantValueDescription
QPalette::Disabled1 
QPalette::Active0 
QPalette::Inactive2 
QPalette::NormalActivesynonym for Active

The ColorRole enum defines the different symbolic color roles used in current GUIs.

Color Roles

The central roles are:

ConstantValueDescription
QPalette::Window10 A general background color.
QPalette::BackgroundWindow This value is obsolete. Use Window instead.
QPalette::WindowText0 A general foreground color.
QPalette::ForegroundWindowText This value is obsolete. Use WindowText instead.
QPalette::Base9 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::AlternateBase16 Used as the alternate background color in views with alternating row colors (refer to QAbstractItemView::setAlternatingRowColors()).
QPalette::ToolTipBase18 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::ToolTipText19 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::Text6 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::Button1 The general button background color. This background can be different from Window as some styles require a different background color for buttons.
QPalette::ButtonText8 A foreground color used with the Button color.
QPalette::BrightText7 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.

ConstantValueDescription
QPalette::Light2Lighter than Button color
QPalette::Midlight3Between Button and Light
QPalette::Dark4Darker than Button
QPalette::Mid5Between Button and Dark
QPalette::Shadow11A very dark color, by default the shadow color is Qt::black
QPalette::Highlight12A color to indicate a selected item or the current item, by default the highlight color is Qt::darkBlue
QPalette::HighlightedText13A text color which contrasts with Highlight, by default the highlighted text color is Qt::white
QPalette::Link14A text color used for unvisited hyperlinks, by default the link color is Qt::blue
QPalette::LinkVisited15A text color used for already visited hyperlinks, by default the linkvisited color is Qt::magenta
QPalette::NoRole17No 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.

QTextBrowser browser;
QColor linkColor(Qt::red);
QString sheet = QString::fromLatin1("a { text-decoration: underline; color: %1 }").formatArg(linkColor.name());
browser.document()->setDefaultStyleSheet(sheet);

Constructor & Destructor Documentation

QPalette::QPalette ( )

Constructs a palette object that uses the application's default palette.

See also
QApplication::setPalette(), QApplication::palette()
QPalette::QPalette ( const QColor button)

Constructs a palette from the button color. The other colors are automatically calculated, based on this color. Window will be the button color as well.

QPalette::QPalette ( Qt::GlobalColor  button)

Constructs a palette from the button color. The other colors are automatically calculated, based on this color. Window will be the button color as well.

QPalette::QPalette ( const QColor button,
const QColor window 
)

Constructs a palette from a button color and a window. The other colors are automatically calculated, based on these colors.

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 
)

Constructs a palette. You can pass either brushes, pixmaps or plain colors for windowText, button, light, dark, mid, text, bright_text, base and window.

See also
QBrush
QPalette::QPalette ( const QColor windowText,
const QColor window,
const QColor light,
const QColor dark,
const QColor mid,
const QColor text,
const QColor base 
)
deprecated
Deprecated:
Constructs a palette with the specified windowText, window, light, dark, mid, text, and base colors. The button color will be set to the window color.
QPalette::QPalette ( const QPalette &  other)

Copy constructs a new QPalette from other.

QPalette::QPalette ( QPalette &&  other)
inline

Move constructs a new QPalette from other.

QPalette::~QPalette ( )

Destroys the palette.

Method Documentation

const QBrush & QPalette::alternateBase ( ) const
inline

Returns the alternate base brush of the current color group.

See also
ColorRole, brush()
const QBrush & QPalette::background ( ) const
inlinedeprecated
Deprecated:
Use window() instead.
const QBrush & QPalette::base ( ) const
inline

Returns the base brush of the current color group.

See also
ColorRole, brush()
const QBrush & QPalette::brightText ( ) const
inline

Returns the bright text foreground brush of the current color group.

See also
ColorRole, brush()
const QBrush & QPalette::brush ( ColorGroup  group,
ColorRole  role 
) const

Returns the brush in the specified color group, used for the given color role.

See also
color(), setBrush(), ColorRole
const QBrush & QPalette::brush ( ColorRole  role) const
inline

Returns the brush that has been set for the given color role in the current ColorGroup.

See also
color(), setBrush(), ColorRole
const QBrush & QPalette::button ( ) const
inline

Returns the button brush of the current color group.

See also
ColorRole, brush()
const QBrush & QPalette::buttonText ( ) const
inline

Returns the button text foreground brush of the current color group.

See also
ColorRole, brush()
qint64 QPalette::cacheKey ( ) const

Returns a number that identifies the contents of this QPalette object. Distinct QPalette objects can have the same key if they refer to the same contents.

The cacheKey() will change when the palette is altered.

const QColor & QPalette::color ( ColorGroup  group,
ColorRole  role 
) const
inline

Returns the color in the specified color group, used for the given color role.

See also
brush(), setColor(), ColorRole
const QColor & QPalette::color ( ColorRole  role) const
inline

Returns the color that has been set for the given color role in the current ColorGroup.

See also
brush(), ColorRole
ColorGroup QPalette::currentColorGroup ( ) const
inline

Returns the palette's current color group.

See also
setCurrentColorGroup()
const QBrush & QPalette::dark ( ) const
inline

Returns the dark brush of the current color group.

See also
ColorRole, brush()
const QBrush & QPalette::foreground ( ) const
inlinedeprecated
const QBrush & QPalette::highlight ( ) const
inline

Returns the highlight brush of the current color group.

See also
ColorRole, brush()
const QBrush & QPalette::highlightedText ( ) const
inline

Returns the highlighted text brush of the current color group.

See also
ColorRole, brush()
bool QPalette::isBrushSet ( ColorGroup  group,
ColorRole  role 
) const

Returns true if the ColorGroup group and ColorRole role has been set previously on this palette, otherwise returns false.

See also
setBrush()
bool QPalette::isCopyOf ( const QPalette &  other) const

Returns true if this palette and other are copies of each other, i.e. one of them was created as a copy of the other and neither was subsequently modified, otherwise returns false. This is much stricter than equality.

See also
operator=(), operator==()
bool QPalette::isEqual ( ColorGroup  group1,
ColorGroup  group2 
) const

Returns true (usually quickly) if color group group1 is equal to group2, otherwise returns false.

const QBrush & QPalette::light ( ) const
inline

Returns the light brush of the current color group.

See also
ColorRole, brush()
const QBrush & QPalette::link ( ) const
inline

Returns the unvisited link text brush of the current color group.

See also
ColorRole, brush()
const QBrush & QPalette::linkVisited ( ) const
inline

Returns the visited link text brush of the current color group.

See also
ColorRole, brush()
const QBrush & QPalette::mid ( ) const
inline

Returns the mid brush of the current color group.

See also
ColorRole, brush()
const QBrush & QPalette::midlight ( ) const
inline

Returns the midlight brush of the current color group.

See also
ColorRole, brush()
QPalette::operator QVariant ( ) const

Returns the palette as a QVariant

bool QPalette::operator!= ( const QPalette &  other) const
inline

Returns true if this palette is different from other, otherwise returns false (usually quickly). The current ColorGroup is not taken into account when comparing palettes.

See also
operator==()
QPalette & QPalette::operator= ( const QPalette &  other)

Copy assigns from other and returns a reference to this object.

QPalette & QPalette::operator= ( QPalette &&  other)
inline

Move assigns from other and returns a reference to this object.

bool QPalette::operator== ( const QPalette &  other) const

Returns true if this palette is equal to other, otherwise returns false. The current ColorGroup is not taken into account when comparing palettes.

See also
operator!=()
QPalette QPalette::resolve ( const QPalette &  other) const

Returns a new QPalette that has attributes copied from other.

void QPalette::setBrush ( ColorGroup  group,
ColorRole  role,
const QBrush brush 
)

Sets the brush in the specified color group, used for the given color role, to brush.

See also
brush(), setColor(), ColorRole
void QPalette::setBrush ( ColorRole  role,
const QBrush brush 
)
inline

Sets the brush for the given color role to the specified brush for all groups in the palette.

See also
brush(), setColor(), ColorRole
void QPalette::setColor ( ColorGroup  group,
ColorRole  role,
const QColor color 
)
inline

Sets the color in the specified color group, used for the given color role, to the specified solid color.

See also
setBrush(), color(), ColorRole
void QPalette::setColor ( ColorRole  role,
const QColor color 
)
inline

Sets the color used for the given color role, in all color groups, to the specified solid color.

See also
brush(), setColor(), ColorRole
void QPalette::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 
)

Sets a the group at group. You can pass either brushes, pixmaps or plain colors for windowText, button, light, dark, mid, text, bright_text, base, and window.

See also
QBrush
void QPalette::setCurrentColorGroup ( ColorGroup  group)
inline

Set the palette's current color group to group.

See also
currentColorGroup()
const QBrush & QPalette::shadow ( ) const
inline

Returns the shadow brush of the current color group.

See also
ColorRole, brush()
void QPalette::swap ( QPalette &  other)
inline

Swaps the palette other with this palette. This operation is very fast and never fails.

const QBrush & QPalette::text ( ) const
inline

Returns the text foreground brush of the current color group.

See also
ColorRole, brush()
const QBrush & QPalette::toolTipBase ( ) const
inline

Returns the tool tip base brush of the current color group. This brush is used by QToolTip and QWhatsThis.

Note
Tool tips use the Inactive color group of QPalette, because tool tips are not active windows.
See also
ColorRole, brush()
const QBrush & QPalette::toolTipText ( ) const
inline

Returns the tool tip text brush of the current color group. This brush is used by QToolTip and QWhatsThis.

Note
Tool tips use the Inactive color group of QPalette, because tool tips are not active windows.
See also
ColorRole, brush()
const QBrush & QPalette::window ( ) const
inline

Returns the window (general background) brush of the current color group.

See also
ColorRole, brush()
const QBrush & QPalette::windowText ( ) const
inline

Returns the window text (general foreground) brush of the current color group.

See also
ColorRole, brush()

Friends And Related Function Documentation

QDataStream & operator<< ( QDataStream stream,
const QPalette &  palette 
)
friend

Writes the palette to the stream and returns a reference to the stream.

Refer to Serializing Data Types for additional information.

QDataStream & operator>> ( QDataStream stream,
QPalette &  palette 
)
related

Reads a palette from the stream and returns a reference to the stream.

Refer to Serializing Data Types for additional information.