The QColor class provides colors based on RGB. More...
#include <qcolor.h>
A color is normally specified in terms of RGB (red,green and blue) components, but it is also possible to specify HSV (hue,saturation and value) or set a color name (X11 color database, no support yet on other window systems).
In addition to the RGB value, a QColor also has a pixel value. This value is used by the underlying window system to refer to a color. It can be thought of as an index into the display hardware's color table.
There are 19 predefined global QColor objects:
black, white, darkGray, gray, lightGray, red, green, blue, cyan, magenta, yellow, darkRed, darkGreen, darkBlue, darkCyan, darkMagenta, darkYellow, color0
and
color1.
The colors color0
(zero pixel value) and color1
(non-zero pixel value)
are special colors for drawing in bitmaps.
The QColor class has an efficient, dynamic color allocation strategy. A color is normally allocated the first time it is used (lazy allocation), that is, whenever the pixel() function is called:
See also: QPalette and QColorGroup.
Examples: xshape/xshape.cpp forever/forever.cpp connect/connect.cpp picture/makepic.cpp drawdemo/drawdemo.cpp widgets/widgets.cpp
Constructs a color with a RGB value and a custom pixel value.
If the pix = 0xffffffff, then the color uses the RGB value in a standard way. If pix is something else, then the pixel value will be set directly to pix (skips the standard allocation procedure).
Constructs a color that is a copy of c.
Constructs a named color, i.e. loads the color from the color database.
See also: setNamedColor().
Constructs a color with the RGB value (r,g,b).
r, g and b must be in the rangle 0..255.
See also: setRgb().
Constructs a color with the RGB or HSV value (x,y,z).
The (x,y,z) triplet defines an RGB value if colorSpec == QColor::Rgb.
x (red), y (green) and z (blue) must be in the
range 0..255.
The (x,y,z) triplet defines a HSV value if colorSpec == QColor::Hsv.
x (hue) must be in the range -1..360 (-1 means
achromatic), and y (saturation) and z (value) must be in the range
0..255.
See also: setRgb() and setHsv().
Constructs an invalid color with the RGB value (0,0,0). An invalid color is a color that is not properly set up for the underlying window system.
See also: isValid().
Allocates the RGB color and returns the pixel value.
Allocating a color means to obtain a pixel value from the RGB specification. The pixel value is an index into the global color table.
Calling the pixel() function will allocate automatically if the color was not already allocated.
Returns the blue component of the RGB value.
[static]
Internal clean up required for QColor. This function is called from the QApplication destructor.
See also: initialize().
Returns a darker (or lighter) color.
Returns a darker color if factor is greater than 100. Setting factor to 300 returns a color that has one third the brightness.
Returns a lighter color if factor is less than 100, equal to light(10000 / factor).
This function converts the current RGB color to HSV, divides V by factor and converts back to RGB.
See also: light().
Examples: widgets/widgets.cpp
Returns the green component of the RGB value.
Returns the current RGB value as HSV.
Arguments:
[static]
Internal initialization required for QColor. This function is called from the QApplication constructor.
See also: cleanup().
Returns TRUE if the color is dirty, i.e. lazy allocation is enabled and an RGB/HSV value has been set but not allocated.
See also: setLazyAlloc(), alloc() and pixel().
Returns TRUE if the color is invalid, i.e. it was constructed using the default constructor.
[static]
Returns TRUE if lazy color allocation is enabled (on-demand allocation), or FALSE if it is disabled (immediate allocation).
See also: setLazyAlloc().
Returns a lighter (or darker) color.
Returns a lighter color if factor is greater than 100. Setting factor to 150 returns a color that is 50% brighter.
Returns a darker color if factor is less than 100, equal to dark(10000 / factor).
This function converts the current RGB color to HSV, multiplies V with factor and converts back to RGB.
See also: dark().
Examples: widgets/widgets.cpp
[static]
Returns the maximum number of colors supported by the underlying window system.
[static]
Returns the number of color bit planes for the underlying window system.
The returned values is equal to the default pixmap depth; QPixmap::depth().
Returns TRUE if this color has different RGB value from c, or FALSE if they have equal RGB values.
Assigns a copy of the color and
returns a reference to this color.
Returns TRUE if this color has the same RGB value as c, or FALSE if they have different RGB values.
Returns the pixel value.
This value is used by the underlying window system to refer to a color. It can be thought of as an index into the display hardware's color table.
Returns the red component of the RGB value.
Returns the RGB value.
Bits 0-7 = red, bits 8-15 = green, bits 16-23 = blue.
The return type QRgb is equivalent to unsigned int.
Returns the red, green and blue components of the RGB value in *r, *g and *b.
Sets a HSV color value.
Arguments:
Examples: drawdemo/drawdemo.cpp
[static]
Enables or disables lazy color allocation.
If lazy allocation is enabled, colors are allocated the first time they are used (upon calling the pixel() function). If lazy allocation is disabled, colors are allocated when they are constructed or when either setRgb() or setHsv() is called.
Lazy color allocation is enabled by default.
See also: lazyAlloc().
Sets the RGB value to that of the named color.
This function searches the X color database for the color and sets the RGB value. The color will be set to invalid if such a color does not exist.
Sets the RGB value to rgb.
Bits 0-7 = red, bits 8-15 = green, bits 16-23 = blue.
The type QRgb is equivalent to unsigned int.
Sets the RGB value to (r, g, b).
Examples: widgets/widgets.cpp
Writes a color object to the stream.
Serialization format: RGB value serialized as an UINT32.
Reads a color object from the stream.
Returns the red component of the RGB triplet rgb.
See also: qRgb() and QColor::red().
Returns the green component of the RGB triplet rgb.
See also: qRgb() and QColor::green().
Returns the blue component of the RGB triplet rgb.
See also: qRgb() and QColor::blue().
Returns the RGB triplet (r,g,b).
Bits 0-7 = r (red), bits 8-15 = g (green), bits 16-23 = b (blue).
The return type QRgb is equivalent to unsigned int.
See also: qRed(), qGreen() and qBlue().
Returns a gray value 0..255 from the (r,g,b) triplet.
The gray value is calculated using the formula:
(r*11 + g*16 + b*5)/32
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it takes.
This file is part of the Qt toolkit, copyright © 1995-96 Troll Tech, all rights reserved.
It was generated from the following files: