Qt logo

QPalette Class Reference


The QPalette class contains color groups for each widget state. More...

#include <qpalette.h>

List of all member functions.

Public Members

Related Functions

(Note that these are not member functions.)

Detailed Description

The QPalette class contains color groups for each widget state.

A palette consists of three color groups: a normal, a disabled and an active color group. All widgets contain a palette, and all the widgets in Qt use their palette to draw themselves. This makes the user interface consistent and easily configurable.

If you make a new widget you are strongly advised to use the colors in the palette rather than hard-coding specific colors.

The active group is used for the widget in focus. Normally it contains the same colors as normal so as not to overwhelm the user with bright and flashing colors, but if you need to you can change it.

The disabled group is used for widgets that are currently inactive or not usable.

The normal color group is used in all other cases.

See also: QApplication::setPalette(), QWidget::setPalette(), QColorGroup and QColor.


Member Function Documentation

QPalette::QPalette ()

Constructs a palette that consists of color groups with only black colors.

QPalette::QPalette ( const QColor & button )

This function is obsolete. It is provided to keep old programs working. We strongly advise against using it in new code.

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

QPalette::QPalette ( const QColor & button, const QColor & background )

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

QPalette::QPalette ( const QColorGroup & normal, const QColorGroup & disabled, const QColorGroup & active )

Constructs a palette that consists of the three color groups normal, disabled and active.

QPalette::QPalette ( const QPalette & p )

Constructs a palette that is a shallow copy of p.

See also: copy().

QPalette::~QPalette ()

Destroys the palette.

const QColorGroup & QPalette::active () const

Returns the active color group of this palette.

See also: QColorGroup, normal(), disabled() and setActive().

const QBrush & QPalette::brush ( ColorGroup gr, QColorGroup::ColorRole r ) const

Returns the brush in gr used for color role r.

const QColor & QPalette::color ( ColorGroup gr, QColorGroup::ColorRole r ) const

Returns the color in gr used for color role r.

See also: brush().

QPalette QPalette::copy () const

Returns a deep copy of the palette.

const QColorGroup & QPalette::disabled () const

Returns the disabled color group of this palette.

See also: QColorGroup, normal(), active() and setDisabled().

bool QPalette::isCopyOf ( const QPalette & p )

Returns TRUE if this palette and p are copies of each other, ie. one of them was created as a copy of the other and neither was subsequently modified. This is much stricter than equality.

See also: operator= and operator==.

const QColorGroup & QPalette::normal () const

Returns the normal color group of this palette.

See also: QColorGroup, disabled(), active() and setNormal().

bool QPalette::operator!= ( const QPalette & p ) const

Returns TRUE if this palette is different from p, or FALSE if they are equal.

QPalette & QPalette::operator= ( const QPalette & p )

Assigns p to this palette and returns a reference to this palette. Note that a shallow copy of p is used.

See also: copy().

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

Returns TRUE if this palette is equal to p, or FALSE if they are different.

int QPalette::serialNumber () const

Returns a number that uniquely identifies this QPalette object. The serial number is very useful for caching.

See also: QPixmap and QPixmapCache.

void QPalette::setActive ( const QColorGroup & g )

Sets the active color group to g.

See also: active().

void QPalette::setBrush ( ColorGroup gr,QColorGroup::ColorRole r,const QBrush & b )

Sets the brush in gr used for color role r to b.

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

Sets the brush in all color groups (Normal, Disabled, and Active) that is used for color role r to b.

void QPalette::setColor ( ColorGroup gr,QColorGroup::ColorRole r,const QColor & c )

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

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

Sets the color of the brush in gr used for color role r to c.

void QPalette::setDisabled ( const QColorGroup & g )

Sets the disabled color group to g.

See also: disabled().

void QPalette::setNormal ( const QColorGroup & g )

Sets the normal color group to g.

See also: normal().


Related Functions

QDataStream & operator>> (QDataStream & s, QPalette & p)

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

QDataStream & operator<< (QDataStream & s, const QPalette & p)

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

Serialization format:

  1. QColorGroup normal
  2. QColorGroup disabled
  3. QColorGroup active
The color groups are serialized in the listed order.

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


This file is part of the Qt toolkit, copyright © 1995-99 Troll Tech, all rights reserved.


Copyright © 1999 Troll TechTrademarks
Qt version 2.0.2