| Classes - Annotated - Tree - Functions - Home - Structure

# QColorGroup Class Reference

The QColorGroup class contains a group of widget colors. More...

`#include <qpalette.h>`

List of all member functions.

## Public Members

- QColorGroup ()
- QColorGroup ( const QColor & foreground, const QColor & button, const QColor & light, const QColor & dark, const QColor & mid, const QColor & text, const QColor & base ) (obsolete)
- QColorGroup ( const QBrush & foreground, const QBrush & button, const QBrush & light, const QBrush & dark, const QBrush & mid, const QBrush & text, const QBrush & bright_text, const QBrush & base, const QBrush & background )
- QColorGroup ( const QColorGroup & )
- ~QColorGroup ()
- enum ColorRole { Foreground, Button, Light, Midlight, Dark, Mid, Text, BrightText, ButtonText, Base, Background, Shadow, Highlight, HighlightedText, NColorRoles }
- const QColor& color ( ColorRole ) const
- const QBrush& brush ( ColorRole ) const
- void setColor ( ColorRole, const QColor & )
- void setBrush ( ColorRole, const QBrush & )
- const QColor& foreground () const
- const QColor& button () const
- const QColor& light () const
- const QColor& dark () const
- const QColor& mid () const
- const QColor& text () const
- const QColor& base () const
- const QColor& background () const
- const QColor& midlight () const
- const QColor& brightText () const
- const QColor& buttonText () const
- const QColor& shadow () const
- const QColor& highlight () const
- const QColor& highlightedText () const
- bool operator== ( const QColorGroup & g ) const
- bool operator!= ( const QColorGroup & g ) const

## Related Functions

(Note that these are not member functions.)

- QDataStream & operator<< (QDataStream & s, const QColorGroup & g)
- QDataStream & operator>> (QDataStream & s, QColorGroup & g)

## Detailed Description

The QColorGroup class contains a group of widget colors.

A color group contains a group of colors used by widgets for drawing themselves. Widgets should not use colors like "red" and "turqoise" but rather "foreground" and "base", where possible. The color roles are enumerated and defined in the ColorRole documentation.

The most common usage of QColorGroup is like this:

        QPainter p;
        ...
        p.setPen( colorGroup().foreground() );
        p.drawLine( ... )

See the ColorRole documentation below for more details on roles.

It's also possible to modify color groups or create them from scratch.

The color group class can be created using three different constructors, or by modifying one supplied by the system. The default constructor creates an all-black color group, which can then be modified using set functions. There are two functions that take long lists of arguments (slightly different lists - beware!). And there is the copy constructor.

We strongly recommend using a system-supplied color group, and modifying that as necessary.

You modify a color group by calling the access functions setColor() and setBrush(), depending on whether you want a pure color or e.g. a pixmap pattern.

There are also corresponding color() and brush() getters, and a commonly used convenience function to get each ColorRole: background(), foreground(), base() and so on.

See also QColor, QPalette and QWidget::colorGroup().

## Member Type Documentation

### QColorGroup::ColorRole

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

- `Background` - general background color.
- `Foreground` - general foreground color.
- `Base` - used as background color for e.g. text entry widgets, usually white or another light color.
- `Text` - the foreground color used with `Base.` Usually this is the same as the `Foreground,` in what case it must provide good contrast both with `Background` and `Base.`
- `Button` - general button background color, where buttons need a background different from `Background,` as in the Macintosh style.
- `ButtonText` - a foreground color used with the `Button` color.

There are some color roles used mostly for 3D bevel and shadow effects:

- `Light` - lighter than `Button` color.
- `Midlight` - between `Button` and `Light.`
- `Dark` - darker than `Button.`
- `Mid` - between `Button` and `Dark.`
- `Shadow` - a very dark color.

All of these are normally derived from `Background,` and used in ways that depend on that relationship. For example, buttons depend on it to make the bevels look good, and Motif scroll bars depend on `Mid` to be slightly different from `Background.`

Selected (marked) items have two roles:

- `Highlight` - a color to indicate a selected or highlighted item.
- `HighlightedText` - a text color that contrasts to `Highlight.`

Finally, there is a special role for text that needs to be drawn where `Text` or `Foreground` would provide bad contrast, such as on pressed push buttons:

- `BrightText` - a text color that is very different from `Foreground` and contrasts well with e.g. `Dark.`

Note that text colors can be used for other things than just words: text colors are usually used for text, but it's quite common to have lines, icons and so on that belong with a text color logically.

This image shows most of the color roles in use:

## Member Function Documentation

### QColorGroup::QColorGroup ()

Constructs a color group with all colors set to black.

### QColorGroup::QColorGroup ( const QBrush & foreground, const QBrush & button, const QBrush & light, const QBrush & dark, const QBrush & mid, const QBrush & text, const QBrush & bright_text, const QBrush & base, const QBrush & background )

Constructs a color group. You can pass either brushes, pixmaps or plain colors for each parameter.

This constructor can be very handy sometimes, but don't overuse it: Such long lists of arguments are rather error-prone.

See also QBrush.

### QColorGroup::QColorGroup ( const QColor & foreground, const QColor & background, const QColor & light, const QColor & dark, const QColor & mid, const QColor & text, const QColor & base )

This function is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.

Constructs a color group with the specified colors. The button color will be set to the background color.

### QColorGroup::QColorGroup ( const QColorGroup & other )

Constructs a color group that is an independent copy of other.

### QColorGroup::~QColorGroup ()

Destructs the color group.

### const QColor & QColorGroup::background () const

Returns the background color of the color group.

See also ColorRole.

### const QColor & QColorGroup::base () const

Returns the base color of the color group.

See also ColorRole.

### const QColor & QColorGroup::brightText () const

Returns the bright text foreground color of the color group.

See also ColorRole.

### const QBrush & QColorGroup::brush ( ColorRole r ) const

Returns the brush that has been set for color role r.

See also color(), setBrush() and ColorRole.

### const QColor & QColorGroup::button () const

Returns the button color of the color group.

See also ColorRole.

### const QColor & QColorGroup::buttonText () const

Returns the button text foreground color of the color group.

See also ColorRole.

### const QColor & QColorGroup::color ( ColorRole r ) const

Returns the color that has been set for color role r.

See also brush() and ColorRole.

### const QColor & QColorGroup::dark () const

Returns the dark color of the color group.

See also ColorRole.

### const QColor & QColorGroup::foreground () const

Returns the foreground color of the color group.

See also ColorRole.

### const QColor & QColorGroup::highlight () const

Returns the highlight color of the color group.

See also ColorRole.

### const QColor & QColorGroup::highlightedText () const

Returns the highlighted text color of the color group.

See also ColorRole.

### const QColor & QColorGroup::light () const

Returns the light color of the color group.

See also ColorRole.

### const QColor & QColorGroup::mid () const

Returns the medium color of the color group.

See also ColorRole.

### const QColor& QColorGroup::midlight () const

Returns the midlight color of the color group.

See also ColorRole.

### bool QColorGroup::operator!= ( const QColorGroup & g ) const

Returns TRUE if this color group is different from g, or FALSE if it is equal to g.

See also operator!=().

### bool QColorGroup::operator== ( const QColorGroup & g ) const

Returns TRUE if this color group is equal to g, or FALSE if it is different from g.

See also operator==().

### void QColorGroup::setBrush ( ColorRole r, const QBrush & b )

Sets the brush used for color role r to b.

See also brush(), setColor() and ColorRole.

### void QColorGroup::setColor ( ColorRole r, const QColor & c )

Sets the brush used for color role r to a solid color c.

See also brush(), setColor() and ColorRole.

### const QColor & QColorGroup::shadow () const

Returns the shadow color of the color group.

See also ColorRole.

### const QColor & QColorGroup::text () const

Returns the text foreground color of the color group.

See also ColorRole.

## Related Functions

### QDataStream & operator<< (QDataStream & s, const QColorGroup & g)

Writes a color group to the stream.

See also Format of the QDataStream operators

### QDataStream & operator>> (QDataStream & s, QColorGroup & g)

Reads a color group from the stream.

See also Format of the QDataStream operators

Search the documentation, FAQ, qt-interest archive and more (uses www.trolltech.com):

This file is part of the Qt toolkit, copyright © 1995-2001 Trolltech, all rights reserved.