TQColorGroup Class

Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# TQColorGroup Class Reference

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

`#include <ntqpalette.h>`

List of all member functions.

## Public Members

- TQColorGroup ()
- TQColorGroup ( const TQColor & foreground, const TQColor & background, const TQColor & light, const TQColor & dark, const TQColor & mid, const TQColor & text, const TQColor & base ) (obsolete)
- TQColorGroup ( const TQBrush & foreground, const TQBrush & button, const TQBrush & light, const TQBrush & dark, const TQBrush & mid, const TQBrush & text, const TQBrush & bright_text, const TQBrush & base, const TQBrush & background )
- TQColorGroup ( const TQColorGroup & other )
- ~TQColorGroup ()
- TQColorGroup & operator= ( const TQColorGroup & other )
- enum ColorRole { Foreground, Button, Light, Midlight, Dark, Mid, Text, BrightText, ButtonText, Base, Background, Shadow, Highlight, HighlightedText, Link, LinkVisited, NColorRoles }
- const TQColor & color ( ColorRole r ) const
- const TQBrush & brush ( ColorRole r ) const
- void setColor ( ColorRole r, const TQColor & c )
- void setBrush ( ColorRole r, const TQBrush & b )
- const TQColor & foreground () const
- const TQColor & button () const
- const TQColor & light () const
- const TQColor & dark () const
- const TQColor & mid () const
- const TQColor & text () const
- const TQColor & base () const
- const TQColor & background () const
- const TQColor & midlight () const
- const TQColor & brightText () const
- const TQColor & buttonText () const
- const TQColor & shadow () const
- const TQColor & highlight () const
- const TQColor & highlightedText () const
- const TQColor & link () const
- const TQColor & linkVisited () const
- bool operator== ( const TQColorGroup & g ) const
- bool operator!= ( const TQColorGroup & g ) const

## Related Functions

- TQDataStream & operator<< ( TQDataStream & s, const TQColorGroup & g )

## Detailed Description

The TQColorGroup class contains a group of widget colors.

A color group contains a group of colors used by widgets for drawing themselves. We recommend that widgets use color group roles such as "foreground" and "base" rather than literal colors like "red" or "turquoise". The color roles are enumerated and defined in the ColorRole documentation.

The most common use of TQColorGroup is like this:

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

It is also possible to modify color groups or create new color groups from scratch.

The color group class can be created using three different constructors or by modifying one supplied by TQt. The default constructor creates an all-black color group, which can then be modified using set functions; there's also a constructor for specifying all the color group colors. And there is also a 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 a pixmap pattern.

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

See also TQColor, TQPalette, TQWidget::colorGroup, Widget Appearance and Style, Graphics Classes, and Image Processing Classes.

## Member Type Documentation

### TQColorGroup::ColorRole

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

The central roles are:

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

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

- `TQColorGroup::Light` - lighter than Button color.
- `TQColorGroup::Midlight` - between Button and Light.
- `TQColorGroup::Dark` - darker than Button.
- `TQColorGroup::Mid` - between Button and Dark.
- `TQColorGroup::Shadow` - a very dark color. By default, the shadow color is `TQt::black`.

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 attractive, and Motif scroll bars depend on Mid to be slightly different from Background.

Selected (marked) items have two roles:

- `TQColorGroup::Highlight` - a color to indicate a selected item or the current item. By default, the highlight color is `TQt::darkBlue`.
- `TQColorGroup::HighlightedText` - a text color that contrasts with Highlight. By default, the highlighted text color is `TQt::white`.

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

- `TQColorGroup::BrightText` - a text color that is very different from Foreground and contrasts well with e.g. Dark.
- `TQColorGroup::Link` - a text color used for unvisited hyperlinks. By default, the link color is `TQt::blue`.
- `TQColorGroup::LinkVisited` - a text color used for already visited hyperlinks. By default, the linkvisited color is `TQt::magenta`.
- `TQColorGroup::NColorRoles` - Internal.

Note that text colors can be used for things other than just words; text colors are usually used for text, but it's quite common to use the text color roles for lines, icons, etc.

This image shows most of the color roles in use:

## Member Function Documentation

### TQColorGroup::TQColorGroup ()

Constructs a color group with all colors set to black.

### TQColorGroup::TQColorGroup ( const TQColor & foreground, const TQColor & background, const TQColor & light, const TQColor & dark, const TQColor & mid, const TQColor & text, const TQColor & base )

This function is obsolete. It is provided to keep old source working. 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.

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

Constructs a color group. You can pass either brushes, pixmaps or plain colors for foreground, button, light, dark, mid, text, bright_text, base and background.

See also TQBrush.

### TQColorGroup::TQColorGroup ( const TQColorGroup & other )

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

### TQColorGroup::~TQColorGroup ()

Destroys the color group.

### const TQColor & TQColorGroup::background () const

Returns the background color of the color group.

See also ColorRole.

### const TQColor & TQColorGroup::base () const

Returns the base color of the color group.

See also ColorRole.

### const TQColor & TQColorGroup::brightText () const

Returns the bright text foreground color of the color group.

See also ColorRole.

Examples: themes/metal.cpp and themes/wood.cpp.

### const TQBrush & TQColorGroup::brush ( ColorRole r ) const

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

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

Examples: themes/metal.cpp and themes/wood.cpp.

### const TQColor & TQColorGroup::button () const

Returns the button color of the color group.

See also ColorRole.

Examples: themes/metal.cpp and themes/wood.cpp.

### const TQColor & TQColorGroup::buttonText () const

Returns the button text foreground color of the color group.

See also ColorRole.

Examples: themes/metal.cpp and themes/wood.cpp.

### const TQColor & TQColorGroup::color ( ColorRole r ) const

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

See also brush() and ColorRole.

### const TQColor & TQColorGroup::dark () const

Returns the dark color of the color group.

See also ColorRole.

Example: themes/wood.cpp.

### const TQColor & TQColorGroup::foreground () const

Returns the foreground color of the color group.

See also ColorRole.

Examples: themes/metal.cpp and themes/wood.cpp.

### const TQColor & TQColorGroup::highlight () const

Returns the highlight color of the color group.

See also ColorRole.

### const TQColor & TQColorGroup::highlightedText () const

Returns the highlighted text color of the color group.

See also ColorRole.

### const TQColor & TQColorGroup::light () const

Returns the light color of the color group.

See also ColorRole.

Example: themes/wood.cpp.

### const TQColor & TQColorGroup::link () const

Returns the unvisited link text color of the color group.

See also ColorRole.

### const TQColor & TQColorGroup::linkVisited () const

Returns the visited link text color of the color group.

See also ColorRole.

### const TQColor & TQColorGroup::mid () const

Returns the mid color of the color group.

See also ColorRole.

Examples: themes/metal.cpp and themes/wood.cpp.

### const TQColor & TQColorGroup::midlight () const

Returns the midlight color of the color group.

See also ColorRole.

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

Returns TRUE if this color group is different from g; otherwise returns FALSE.

See also

### TQColorGroup & TQColorGroup::operator= ( const TQColorGroup & other )

Copies the colors of other to this color group.

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

Returns TRUE if this color group is equal to g; otherwise returns FALSE.

See also

### void TQColorGroup::setBrush ( ColorRole r, const TQBrush & b )

Sets the brush used for color role r to b.

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

Example: themes/wood.cpp.

### void TQColorGroup::setColor ( ColorRole r, const TQColor & c )

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

See also brush() and ColorRole.

Examples: listviews/listviews.cpp, table/statistics/statistics.cpp, and themes/metal.cpp.

### const TQColor & TQColorGroup::shadow () const

Returns the shadow color of the color group.

See also ColorRole.

### const TQColor & TQColorGroup::text () const

Returns the text foreground color of the color group.

See also ColorRole.

Example: listviews/listviews.cpp.

## Related Functions

### TQDataStream & operator<< ( TQDataStream & s, const TQColorGroup & g )

Writes color group, g to the stream s.

See also Format of the TQDataStream operators.

This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.