Logo Search packages:      
Sourcecode: qt4-x11 version File versions  Download package

QColor Class Reference

List of all members.

Detailed Description

The QColor class provides colors based on RGB, HSV or CMYK values.

A color is normally specified in terms of RGB (red, green, and blue) components, but it is also possible to specify it in terms of HSV (hue, saturation, and value) and CMYK (cyan, magenta, yellow and black) components. In addition a color can be specified using a color name. The color name can be any of the SVG 1.0 color names.

qcolor-rgb.png qcolor-hsv.png qcolor-cmyk.png RGB HSV CMYK

The QColor constructor creates the color based on RGB values. To create a QColor based on either HSV or CMYK values, use the toHsv() and toCmyk() functions respectively. These functions return a copy of the color using the desired format. In addition the static fromRgb(), fromHsv() and fromCmyk() functions create colors from the specified values. Alternatively, a color can be converted to any of the three formats using the convertTo() function (returning a copy of the color in the desired format), or any of the setRgb(), setHsv() and setCmyk() functions altering this color's format. The spec() function tells how the color was specified.

A color can be set by passing an RGB string (such as "#112233"), or a color name (such as "blue"), to the setNamedColor() function. The color names are taken from the SVG 1.0 color names. The name() function returns the name of the color in the format AARRGGBB. Colors can also be set using setRgb(), setHsv() and setCmyk(). To get a lighter or darker color use the light() and dark() functions respectively.

The isValid() function indicates whether a QColor is legal at all. For example, a RGB color with RGB values out of range is illegal. For performance reasons, QColor mostly disregards illegal colors, and for that reason, the result of using an invalid color is undefined.

The color components can be retrieved individually, e.g with red(), hue() and cyan(). The values of the color components can also be retrieved in one go using the getRgb(), getHsv() and getCmyk() functions. Using the RGB color model, the color components can in addition be accessed with rgb().

There are several related non-members: QRgb is a typdef for an unsigned int representing the RGB value triplet (r, g, b). Note that it also can hold a value for the alpha-channel (for more information, see the {QColor::Alpha-Blended Drawing}{Alpha-Blended Drawing} section). The qRed(), qBlue() and qGreen() functions return the respective component of the given QRgb value, while the qRgb() and qRgba() functions create and return the QRgb triplet based on the given component values. Finally, the qAlpha() function returns the alpha component of the provided QRgb, and the qGray() function calculates and return a gray value based on the given value.

QColor is platform and device independent. The QColormap class maps the color to the hardware.

Definition at line 45 of file qcolor.h.

Public Types

enum  Spec { Invalid, Rgb, Hsv, Cmyk }

Public Member Functions

int alpha () const
qreal alphaF () const
int black () const
qreal blackF () const
int blue () const
qreal blueF () const
QColor convertTo (Spec colorSpec) const
int cyan () const
qreal cyanF () const
QColor dark (int f=200) const
void getCmyk (int *c, int *m, int *y, int *k, int *a=0)
void getCmykF (qreal *c, qreal *m, qreal *y, qreal *k, qreal *a=0)
void getHsv (int *h, int *s, int *v, int *a=0) const
void getHsvF (qreal *h, qreal *s, qreal *v, qreal *a=0) const
void getRgb (int *r, int *g, int *b, int *a=0) const
void getRgbF (qreal *r, qreal *g, qreal *b, qreal *a=0) const
int green () const
qreal greenF () const
int hue () const
qreal hueF () const
bool isValid () const
QColor light (int f=150) const
int magenta () const
qreal magentaF () const
QString name () const
 operator QVariant () const
bool operator!= (const QColor &c) const
QColoroperator= (Qt::GlobalColor color)
QColoroperator= (const QColor &)
bool operator== (const QColor &c) const
 QColor (const QColor &color)
 QColor (const char *name)
 QColor (const QString &name)
 QColor (QRgb rgb)
 QColor (int r, int g, int b, int a=255)
 QColor (Qt::GlobalColor color)
 QColor ()
int red () const
qreal redF () const
QRgb rgb () const
QRgb rgba () const
int saturation () const
qreal saturationF () const
void setAlpha (int alpha)
void setAlphaF (qreal alpha)
void setBlue (int blue)
void setBlueF (qreal blue)
void setCmyk (int c, int m, int y, int k, int a=255)
void setCmykF (qreal c, qreal m, qreal y, qreal k, qreal a=1.0)
void setGreen (int green)
void setGreenF (qreal green)
void setHsv (int h, int s, int v, int a=255)
void setHsvF (qreal h, qreal s, qreal v, qreal a=1.0)
void setNamedColor (const QString &name)
void setRed (int red)
void setRedF (qreal red)
void setRgb (QRgb rgb)
void setRgb (int r, int g, int b, int a=255)
void setRgba (QRgb rgba)
void setRgbF (qreal r, qreal g, qreal b, qreal a=1.0)
Spec spec () const
QColor toCmyk () const
QColor toHsv () const
QColor toRgb () const
int value () const
qreal valueF () const
int yellow () const
qreal yellowF () const

Static Public Member Functions

static QStringList colorNames ()
static QColor fromCmyk (int c, int m, int y, int k, int a=255)
static QColor fromCmykF (qreal c, qreal m, qreal y, qreal k, qreal a=1.0)
static QColor fromHsv (int h, int s, int v, int a=255)
static QColor fromHsvF (qreal h, qreal s, qreal v, qreal a=1.0)
static QColor fromRgb (int r, int g, int b, int a=255)
static QColor fromRgb (QRgb rgb)
static QColor fromRgba (QRgb rgba)
static QColor fromRgbF (qreal r, qreal g, qreal b, qreal a=1.0)

Private Member Functions

void invalidate ()
 QColor (int, int, int, Spec)

Private Attributes

Spec cspec
union {
   struct {
      ushort   alpha
      ushort   black
      ushort   cyan
      ushort   magenta
      ushort   yellow
   }   acmyk
   struct {
      ushort   alpha
      ushort   hue
      ushort   pad
      ushort   saturation
      ushort   value
   }   ahsv
   struct {
      ushort   alpha
      ushort   blue
      ushort   green
      ushort   pad
      ushort   red
   }   argb


Q_GUI_EXPORT QDataStreamoperator<< (QDataStream &, const QColor &)
Q_GUI_EXPORT QDataStreamoperator>> (QDataStream &, QColor &)
class QColormap

Related Functions

(Note that these are not member functions.)

int qAlpha (QRgb rgba)
int qBlue (QRgb rgb)
int qGray (QRgb rgb)
int qGray (int r, int g, int b)
int qGreen (QRgb rgb)
int qRed (QRgb rgb)
QRgb qRgb (int r, int g, int b)
QRgb qRgba (int r, int g, int b, int a)

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index