Qt 4.8
Public Types | Public Functions | Static Public Functions | Private Functions | Properties | Friends | Related Functions | List of all members
QColor Class Reference

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

#include <qcolor.h>

Public Types

enum  Spec {
  Invalid, Rgb, Hsv, Cmyk,
  Hsl
}
 The type of color specified, either RGB, HSV, CMYK or HSL. More...
 

Public Functions

int alpha () const
 
qreal alphaF () const
 Returns the alpha color component of this color. More...
 
int black () const
 
qreal blackF () const
 Returns the black color component of this color. More...
 
int blue () const
 
qreal blueF () const
 Returns the blue color component of this color. More...
 
QColor convertTo (Spec colorSpec) const
 Creates a copy of this color in the format specified by colorSpec. More...
 
int cyan () const
 
qreal cyanF () const
 Returns the cyan color component of this color. More...
 
QColor dark (int f=200) const
 Use darker(factor) instead. More...
 
QColor darker (int f=200) const
 Returns a darker (or lighter) color, but does not change this object. More...
 
void getCmyk (int *c, int *m, int *y, int *k, int *a=0)
 Sets the contents pointed to by c, m, y, k, and a, to the cyan, magenta, yellow, black, and alpha-channel (transparency) components of the color's CMYK value. More...
 
void getCmykF (qreal *c, qreal *m, qreal *y, qreal *k, qreal *a=0)
 Sets the contents pointed to by c, m, y, k, and a, to the cyan, magenta, yellow, black, and alpha-channel (transparency) components of the color's CMYK value. More...
 
void getHsl (int *h, int *s, int *l, int *a=0) const
 Sets the contents pointed to by h, s, l, and a, to the hue, saturation, lightness, and alpha-channel (transparency) components of the color's HSL value. More...
 
void getHslF (qreal *h, qreal *s, qreal *l, qreal *a=0) const
 Sets the contents pointed to by h, s, l, and a, to the hue, saturation, lightness, and alpha-channel (transparency) components of the color's HSL value. More...
 
void getHsv (int *h, int *s, int *v, int *a=0) const
 Sets the contents pointed to by h, s, v, and a, to the hue, saturation, value, and alpha-channel (transparency) components of the color's HSV value. More...
 
void getHsvF (qreal *h, qreal *s, qreal *v, qreal *a=0) const
 Sets the contents pointed to by h, s, v, and a, to the hue, saturation, value, and alpha-channel (transparency) components of the color's HSV value. More...
 
void getRgb (int *r, int *g, int *b, int *a=0) const
 Sets the contents pointed to by r, g, b, and a, to the red, green, blue, and alpha-channel (transparency) components of the color's RGB value. More...
 
void getRgbF (qreal *r, qreal *g, qreal *b, qreal *a=0) const
 Sets the contents pointed to by r, g, b, and a, to the red, green, blue, and alpha-channel (transparency) components of the color's RGB value. More...
 
int green () const
 
qreal greenF () const
 Returns the green color component of this color. More...
 
int hslHue () const
 Returns the hue color component of this color. More...
 
qreal hslHueF () const
 Returns the hue color component of this color. More...
 
int hslSaturation () const
 Returns the saturation color component of this color. More...
 
qreal hslSaturationF () const
 Returns the saturation color component of this color. More...
 
int hsvHue () const
 Returns the hue color component of this color. More...
 
qreal hsvHueF () const
 Returns the hue color component of this color. More...
 
int hsvSaturation () const
 Returns the saturation color component of this color. More...
 
qreal hsvSaturationF () const
 Returns the saturation color component of this color. More...
 
int hue () const
 
qreal hueF () const
 Returns the hue color component of this color. More...
 
bool isValid () const
 Returns true if the color is valid; otherwise returns false. More...
 
QColor light (int f=150) const
 Use lighter(factor) instead. More...
 
QColor lighter (int f=150) const
 Returns a lighter (or darker) color, but does not change this object. More...
 
int lightness () const
 
qreal lightnessF () const
 Returns the lightness color component of this color. More...
 
int magenta () const
 
qreal magentaF () const
 Returns the magenta color component of this color. More...
 
QString name () const
 Returns the name of the color in the format "#RRGGBB"; i.e. More...
 
 operator QVariant () const
 Returns the color as a QVariant. More...
 
bool operator!= (const QColor &c) const
 Returns true if this color has a different RGB and alpha values from color; otherwise returns false. More...
 
QColoroperator= (const QColor &)
 Assigns a copy of color to this color, and returns a reference to it. More...
 
QColoroperator= (Qt::GlobalColor color)
 Assigns a copy of color and returns a reference to this color. More...
 
bool operator== (const QColor &c) const
 Returns true if this color has the same RGB and alpha values as color; otherwise returns false. More...
 
 QColor ()
 Constructs an invalid color with the RGB value (0, 0, 0). More...
 
 QColor (Qt::GlobalColor color)
 Constructs a new color with a color value of color. More...
 
 QColor (int r, int g, int b, int a=255)
 Constructs a color with the RGB value r, g, b, and the alpha-channel (transparency) value of a. More...
 
 QColor (QRgb rgb)
 Constructs a color with the value color. More...
 
 QColor (const QString &name)
 Constructs a named color in the same way as setNamedColor() using the given name. More...
 
 QColor (const char *name)
 Constructs a named color in the same way as setNamedColor() using the given name. More...
 
 QColor (const QColor &color)
 Constructs a color that is a copy of color. More...
 
 QColor (Spec spec)
 Constructs a color with the given spec. More...
 
int red () const
 
qreal redF () const
 Returns the red color component of this color. More...
 
QRgb rgb () const
 Returns the RGB value of the color. More...
 
QRgb rgba () const
 Returns the RGB value of the color, including its alpha. More...
 
int saturation () const
 
qreal saturationF () const
 Returns the saturation color component of this color. More...
 
void setAlpha (int alpha)
 Sets the alpha of this color to alpha. More...
 
void setAlphaF (qreal alpha)
 Sets the alpha of this color to alpha. More...
 
void setBlue (int blue)
 Sets the blue color component of this color to blue. More...
 
void setBlueF (qreal blue)
 Sets the blue color component of this color to blue. More...
 
void setCmyk (int c, int m, int y, int k, int a=255)
 Sets the color to CMYK values, c (cyan), m (magenta), y (yellow), k (black), and a (alpha-channel, i.e. More...
 
void setCmykF (qreal c, qreal m, qreal y, qreal k, qreal a=1.0)
 Sets the color to CMYK values, c (cyan), m (magenta), y (yellow), k (black), and a (alpha-channel, i. More...
 
void setGreen (int green)
 Sets the green color component of this color to green. More...
 
void setGreenF (qreal green)
 Sets the green color component of this color to green. More...
 
void setHsl (int h, int s, int l, int a=255)
 Sets a HSL color value; h is the hue, s is the saturation, l is the lightness and a is the alpha component of the HSL color. More...
 
void setHslF (qreal h, qreal s, qreal l, qreal a=1.0)
 Sets a HSL color lightness; h is the hue, s is the saturation, l is the lightness and a is the alpha component of the HSL color. More...
 
void setHsv (int h, int s, int v, int a=255)
 Sets a HSV color value; h is the hue, s is the saturation, v is the value and a is the alpha component of the HSV color. More...
 
void setHsvF (qreal h, qreal s, qreal v, qreal a=1.0)
 Sets a HSV color value; h is the hue, s is the saturation, v is the value and a is the alpha component of the HSV color. More...
 
void setNamedColor (const QString &name)
 Sets the RGB value of this QColor to name, which may be in one of these formats: More...
 
void setRed (int red)
 Sets the red color component of this color to red. More...
 
void setRedF (qreal red)
 Sets the red color component of this color to red. More...
 
void setRgb (int r, int g, int b, int a=255)
 Sets the RGB value to r, g, b and the alpha value to a. More...
 
void setRgb (QRgb rgb)
 Sets the RGB value to rgb. More...
 
void setRgba (QRgb rgba)
 Use setRgb() instead. More...
 
void setRgbF (qreal r, qreal g, qreal b, qreal a=1.0)
 Sets the color channels of this color to r (red), g (green), b (blue) and a (alpha, transparency). More...
 
Spec spec () const
 Returns how the color was specified. More...
 
QColor toCmyk () const
 Creates and returns a CMYK QColor based on this color. More...
 
QColor toHsl () const
 Creates and returns an HSL QColor based on this color. More...
 
QColor toHsv () const
 Creates and returns an HSV QColor based on this color. More...
 
QColor toRgb () const
 Create and returns an RGB QColor based on this color. More...
 
int value () const
 
qreal valueF () const
 Returns the value color component of this color. More...
 
int yellow () const
 
qreal yellowF () const
 Returns the yellow color component of this color. More...
 

Static Public Functions

static bool allowX11ColorNames ()
 Returns true if setNamedColor() is allowed to look up colors in the X11 color database. More...
 
static QStringList colorNames ()
 Returns a QStringList containing the color names Qt knows about. More...
 
static QColor fromCmyk (int c, int m, int y, int k, int a=255)
 Static convenience function that returns a QColor constructed from the given CMYK color values: c (cyan), m (magenta), y (yellow), k (black), and a (alpha-channel, i.e. More...
 
static QColor fromCmykF (qreal c, qreal m, qreal y, qreal k, qreal a=1.0)
 Static convenience function that returns a QColor constructed from the given CMYK color values: c (cyan), m (magenta), y (yellow), k (black), and a (alpha-channel, i. More...
 
static QColor fromHsl (int h, int s, int l, int a=255)
 Static convenience function that returns a QColor constructed from the HSV color values, h (hue), s (saturation), l (lightness), and a (alpha-channel, i. More...
 
static QColor fromHslF (qreal h, qreal s, qreal l, qreal a=1.0)
 Static convenience function that returns a QColor constructed from the HSV color values, h (hue), s (saturation), l (lightness), and a (alpha-channel, i. More...
 
static QColor fromHsv (int h, int s, int v, int a=255)
 Static convenience function that returns a QColor constructed from the HSV color values, h (hue), s (saturation), v (value), and a (alpha-channel, i.e. More...
 
static QColor fromHsvF (qreal h, qreal s, qreal v, qreal a=1.0)
 Static convenience function that returns a QColor constructed from the HSV color values, h (hue), s (saturation), v (value), and a (alpha-channel, i. More...
 
static QColor fromRgb (QRgb rgb)
 Static convenience function that returns a QColor constructed from the given QRgb value rgb. More...
 
static QColor fromRgb (int r, int g, int b, int a=255)
 Static convenience function that returns a QColor constructed from the RGB color values, r (red), g (green), b (blue), and a (alpha-channel, i.e. More...
 
static QColor fromRgba (QRgb rgba)
 Static convenience function that returns a QColor constructed from the given QRgb value rgba. More...
 
static QColor fromRgbF (qreal r, qreal g, qreal b, qreal a=1.0)
 Static convenience function that returns a QColor constructed from the RGB color values, r (red), g (green), b (blue), and a (alpha-channel, i.e. More...
 
static bool isValidColor (const QString &name)
 Returns true if the name is a valid color name and can be used to construct a valid QColor object, otherwise returns false. More...
 
static void setAllowX11ColorNames (bool enabled)
 Allow setNamedColor() to look up colors in the X11 color database if enabled. More...
 

Private Functions

void invalidate ()
 Marks the color as invalid and sets all components to zero (alpha is set to fully opaque for compatibility with Qt 3). More...
 
 QColor (int, int, int, Spec)
 Use one of the other QColor constructors, or one of the static convenience functions, instead. More...
 
bool setColorFromString (const QString &name)
 

Properties

Spec cspec
 
union {
   struct {
      ushort   alpha
 
      ushort   black
 
      ushort   cyan
 
      ushort   magenta
 
      ushort   yellow
 
   }   acmyk
 
   struct {
      ushort   alpha
 
      ushort   hue
 
      ushort   lightness
 
      ushort   pad
 
      ushort   saturation
 
   }   ahsl
 
   struct {
      ushort   alpha
 
      ushort   hue
 
      ushort   pad
 
      ushort   saturation
 
      ushort   value
 
   }   ahsv
 
   struct {
      ushort   alpha
 
      ushort   blue
 
      ushort   green
 
      ushort   pad
 
      ushort   red
 
   }   argb
 
   ushort   array [5]
 
ct
 

Friends

Q_GUI_EXPORT QDataStreamoperator<< (QDataStream &, const QColor &)
 Writes the color to the stream. More...
 
Q_GUI_EXPORT QDataStreamoperator>> (QDataStream &, QColor &)
 Reads the color from the stream. More...
 
class QColormap
 

Related Functions

(Note that these are not member functions.)

int qAlpha (QRgb rgba)
 Returns the alpha component of the ARGB quadruplet rgba. More...
 
int qBlue (QRgb rgb)
 Returns the blue component of the ARGB quadruplet rgb. More...
 
int qGray (int r, int g, int b)
 
int qGray (QRgb rgb)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
int qGreen (QRgb rgb)
 Returns the green component of the ARGB quadruplet rgb. More...
 
int qRed (QRgb rgb)
 Returns the red component of the ARGB quadruplet rgb. More...
 
QRgb qRgb (int r, int g, int b)
 Returns the ARGB quadruplet (255, {r}, {g}, {b}). More...
 
 QRgb
 An ARGB quadruplet on the format #AARRGGBB, equivalent to an unsigned int. More...
 
QRgb qRgba (int r, int g, int b, int a)
 Returns the ARGB quadruplet ({a}, {r}, {g}, {b}). More...
 

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.

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

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 "#RRGGBB". Colors can also be set using setRgb(), setHsv() and setCmyk(). To get a lighter or darker color use the lighter() and darker() 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 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.

For more information about painting in general, see the Paint System documentation.

.-Floating-Point-Precision

Integer vs. Floating Point Precision

QColor supports floating point precision and provides floating point versions of all the color components functions, e.g. getRgbF(), hueF() and fromCmykF(). Note that since the components are stored using 16-bit integers, there might be minor deviations between the values set using, for example, setRgbF() and the values returned by the getRgbF() function due to rounding.

While the integer based functions take values in the range 0-255 (except hue() which must have values within the range 0-359), the floating point functions accept values in the range 0.0 - 1.0.

Alpha-Blended Drawing

QColor also support alpha-blended outlining and filling. The alpha channel of a color specifies the transparency effect, 0 represents a fully transparent color, while 255 represents a fully opaque color. For example:

// Specify semi-transparent red
painter.setBrush(QColor(255, 0, 0, 127));
painter.drawRect(0, 0, width()/2, height());
// Specify semi-transparent blue
painter.setBrush(QColor(0, 0, 255, 127));
painter.drawRect(0, 0, width(), height()/2);

The code above produces the following output:

alphafill.png

Alpha-blended drawing is supported on Windows, Mac OS X, and on X11 systems that have the X Render extension installed.

The alpha channel of a color can be retrieved and set using the alpha() and setAlpha() functions if its value is an integer, and alphaF() and setAlphaF() if its value is qreal (double). By default, the alpha-channel is set to 255 (opaque). To retrieve and set all the RGB color components (including the alpha-channel) in one go, use the rgba() and setRgba() functions.

Predefined Colors

There are 20 predefined QColors described by the Qt::GlobalColor enum, including black, white, primary and secondary colors, darker versions of these colors and three shades of gray. QColor also recognizes a variety of color names; the static colorNames() function returns a QStringList color names that QColor knows about.

qt-colors.png
Qt Colors

Additionally, the Qt::color0, Qt::color1 and Qt::transparent colors are used for special purposes.

Qt::color0 (zero pixel value) and Qt::color1 (non-zero pixel value) are special colors for drawing in QBitmaps. Painting with Qt::color0 sets the bitmap bits to 0 (transparent; i.e., background), and painting with Qt::color1 sets the bits to 1 (opaque; i.e., foreground).

Qt::transparent is used to indicate a transparent pixel. When painting with this value, a pixel value will be used that is appropriate for the underlying pixel format in use.

The HSV Color Model

The RGB model is hardware-oriented. Its representation is close to what most monitors show. In contrast, HSV represents color in a way more suited to the human perception of color. For example, the relationships "stronger than", "darker than", and "the opposite of" are easily expressed in HSV but are much harder to express in RGB.

HSV, like RGB, has three components:

Here are some examples: pure red is H=0, S=255, V=255; a dark red, moving slightly towards the magenta, could be H=350 (equivalent to -10), S=255, V=180; a grayish light red could have H about 0 (say 350-359 or 0-10), S about 50-100, and S=255.

Qt returns a hue value of -1 for achromatic colors. If you pass a hue value that is too large, Qt forces it into range. Hue 360 or 720 is treated as 0; hue 540 is treated as 180.

In addition to the standard HSV model, Qt provides an alpha-channel to feature alpha-blended drawing.

The HSL Color Model

HSL is similar to HSV. Instead of value parameter from HSV, HSL has the lightness parameter. The lightness parameter goes from black to color and from color to white. If you go outside at the night its black or dark gray. At day its colorful but if you look in a really strong light a things they are going to white and wash out.

The CMYK Color Model

While the RGB and HSV color models are used for display on computer monitors, the CMYK model is used in the four-color printing process of printing presses and some hard-copy devices.

CMYK has four components, all in the range 0-255: cyan (C), magenta (M), yellow (Y) and black (K). Cyan, magenta and yellow are called subtractive colors; the CMYK color model creates color by starting with a white surface and then subtracting color by applying the appropriate components. While combining cyan, magenta and yellow gives the color black, subtracting one or more will yield any other color. When combined in various percentages, these three colors can create the entire spectrum of colors.

Mixing 100 percent of cyan, magenta and yellow does produce black, but the result is unsatisfactory since it wastes ink, increases drying time, and gives a muddy colour when printing. For that reason, black is added in professional printing to provide a solid black tone; hence the term 'four color process'.

In addition to the standard CMYK model, Qt provides an alpha-channel to feature alpha-blended drawing.

See also
QPalette, QBrush, QApplication::setColorSpec()

Definition at line 67 of file qcolor.h.

Enumerations

◆ Spec

The type of color specified, either RGB, HSV, CMYK or HSL.

  • Rgb
  • Hsv
  • Cmyk
  • Hsl
  • Invalid
See also
spec(), convertTo()
Enumerator
Invalid 
Rgb 
Hsv 
Cmyk 
Hsl 

Definition at line 70 of file qcolor.h.

Constructors and Destructors

◆ QColor() [1/9]

QColor::QColor ( )
inline

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.

The alpha value of an invalid color is unspecified.

See also
isValid()

Definition at line 279 of file qcolor.h.

Referenced by convertTo(), fromCmyk(), fromCmykF(), fromHsl(), fromHslF(), fromHsv(), fromHsvF(), fromRgb(), fromRgbF(), isValidColor(), and operator=().

280 { invalidate(); }
void invalidate()
Marks the color as invalid and sets all components to zero (alpha is set to fully opaque for compatib...
Definition: qcolor.cpp:2563

◆ QColor() [2/9]

QColor::QColor ( Qt::GlobalColor  color)

Constructs a new color with a color value of color.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

See also
isValid(), {QColor::Predefined Colors}{Predefined Colors}

Definition at line 355 of file qcolor.cpp.

356 {
357 #define QRGB(r, g, b) \
358  QRgb(((0xffu << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff)))
359 #define QRGBA(r, g, b, a) \
360  QRgb(((a & 0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff))
361 
362  static const QRgb global_colors[] = {
363  QRGB(255, 255, 255), // Qt::color0
364  QRGB( 0, 0, 0), // Qt::color1
365  QRGB( 0, 0, 0), // black
366  QRGB(255, 255, 255), // white
367  /*
368  * From the "The Palette Manager: How and Why" by Ron Gery,
369  * March 23, 1992, archived on MSDN:
370  *
371  * The Windows system palette is broken up into two
372  * sections, one with fixed colors and one with colors
373  * that can be changed by applications. The system palette
374  * predefines 20 entries; these colors are known as the
375  * static or reserved colors and consist of the 16 colors
376  * found in the Windows version 3.0 VGA driver and 4
377  * additional colors chosen for their visual appeal. The
378  * DEFAULT_PALETTE stock object is, as the name implies,
379  * the default palette selected into a device context (DC)
380  * and consists of these static colors. Applications can
381  * set the remaining 236 colors using the Palette Manager.
382  *
383  * The 20 reserved entries have indices in [0,9] and
384  * [246,255]. We reuse 17 of them.
385  */
386  QRGB(128, 128, 128), // index 248 medium gray
387  QRGB(160, 160, 164), // index 247 light gray
388  QRGB(192, 192, 192), // index 7 light gray
389  QRGB(255, 0, 0), // index 249 red
390  QRGB( 0, 255, 0), // index 250 green
391  QRGB( 0, 0, 255), // index 252 blue
392  QRGB( 0, 255, 255), // index 254 cyan
393  QRGB(255, 0, 255), // index 253 magenta
394  QRGB(255, 255, 0), // index 251 yellow
395  QRGB(128, 0, 0), // index 1 dark red
396  QRGB( 0, 128, 0), // index 2 dark green
397  QRGB( 0, 0, 128), // index 4 dark blue
398  QRGB( 0, 128, 128), // index 6 dark cyan
399  QRGB(128, 0, 128), // index 5 dark magenta
400  QRGB(128, 128, 0), // index 3 dark yellow
401  QRGBA(0, 0, 0, 0) // transparent
402  };
403 #undef QRGB
404 #undef QRGBA
405 
406  setRgb(qRed(global_colors[color]),
407  qGreen(global_colors[color]),
408  qBlue(global_colors[color]),
409  qAlpha(global_colors[color]));
410 }
void setRgb(int r, int g, int b, int a=255)
Sets the RGB value to r, g, b and the alpha value to a.
Definition: qcolor.cpp:980
unsigned int QRgb
Definition: qrgb.h:53
#define QRGB(r, g, b)
int qRed(QRgb rgb)
Returns the red component of the ARGB quadruplet rgb.
Definition: qrgb.h:57
int qAlpha(QRgb rgba)
Returns the alpha component of the ARGB quadruplet rgba.
Definition: qrgb.h:66
#define QRGBA(r, g, b, a)
int qGreen(QRgb rgb)
Returns the green component of the ARGB quadruplet rgb.
Definition: qrgb.h:60
int qBlue(QRgb rgb)
Returns the blue component of the ARGB quadruplet rgb.
Definition: qrgb.h:63

◆ QColor() [3/9]

QColor::QColor ( int  r,
int  g,
int  b,
int  a = 255 
)
inline

Constructs a color with the RGB value r, g, b, and the alpha-channel (transparency) value of a.

The color is left invalid if any of the arguments are invalid.

See also
setRgba(), isValid()

Definition at line 282 of file qcolor.h.

283 { setRgb(r, g, b, a); }
void setRgb(int r, int g, int b, int a=255)
Sets the RGB value to r, g, b and the alpha value to a.
Definition: qcolor.cpp:980
long ASN1_INTEGER_get ASN1_INTEGER * a

◆ QColor() [4/9]

QColor::QColor ( QRgb  color)

Constructs a color with the value color.

The alpha component is ignored and set to solid.

See also
fromRgb(), isValid()

Definition at line 433 of file qcolor.cpp.

434 {
435  cspec = Rgb;
436  ct.argb.alpha = 0xffff;
437  ct.argb.red = qRed(color) * 0x101;
438  ct.argb.green = qGreen(color) * 0x101;
439  ct.argb.blue = qBlue(color) * 0x101;
440  ct.argb.pad = 0;
441 }
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
int qRed(QRgb rgb)
Returns the red component of the ARGB quadruplet rgb.
Definition: qrgb.h:57
int qGreen(QRgb rgb)
Returns the green component of the ARGB quadruplet rgb.
Definition: qrgb.h:60
int qBlue(QRgb rgb)
Returns the blue component of the ARGB quadruplet rgb.
Definition: qrgb.h:63

◆ QColor() [5/9]

QColor::QColor ( const QString name)
inline

Constructs a named color in the same way as setNamedColor() using the given name.

The color is left invalid if the name cannot be parsed.

See also
setNamedColor(), name(), isValid()

Definition at line 288 of file qcolor.h.

289 { setNamedColor(aname); }
void setNamedColor(const QString &name)
Sets the RGB value of this QColor to name, which may be in one of these formats:
Definition: qcolor.cpp:560

◆ QColor() [6/9]

QColor::QColor ( const char *  name)
inline

Constructs a named color in the same way as setNamedColor() using the given name.

The color is left invalid if the name cannot be parsed.

See also
setNamedColor(), name(), isValid()

Definition at line 285 of file qcolor.h.

286 { setNamedColor(QLatin1String(aname)); }
void setNamedColor(const QString &name)
Sets the RGB value of this QColor to name, which may be in one of these formats:
Definition: qcolor.cpp:560
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString

◆ QColor() [7/9]

QColor::QColor ( const QColor color)
inline

Constructs a color that is a copy of color.

See also
isValid()

Definition at line 291 of file qcolor.h.

292  : cspec(acolor.cspec)
293 { ct.argb = acolor.ct.argb; }
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239

◆ QColor() [8/9]

QColor::QColor ( Spec  spec)

Constructs a color with the given spec.

Warning
This function is not part of the public interface.

This function is primarly present to avoid that QColor::Invalid becomes a valid color by accident.

Definition at line 456 of file qcolor.cpp.

457 {
458  switch (spec) {
459  case Invalid:
460  invalidate();
461  break;
462  case Rgb:
463  setRgb(0, 0, 0);
464  break;
465  case Hsv:
466  setHsv(0, 0, 0);
467  break;
468  case Cmyk:
469  setCmyk(0, 0, 0, 0);
470  break;
471  case Hsl:
472  setHsl(0, 0, 0, 0);
473  break;
474  }
475 }
void setRgb(int r, int g, int b, int a=255)
Sets the RGB value to r, g, b and the alpha value to a.
Definition: qcolor.cpp:980
void invalidate()
Marks the color as invalid and sets all components to zero (alpha is set to fully opaque for compatib...
Definition: qcolor.cpp:2563
void setHsv(int h, int s, int v, int a=255)
Sets a HSV color value; h is the hue, s is the saturation, v is the value and a is the alpha componen...
Definition: qcolor.cpp:734
void setHsl(int h, int s, int l, int a=255)
Sets a HSL color value; h is the hue, s is the saturation, l is the lightness and a is the alpha comp...
Definition: qcolor.cpp:861
Spec spec() const
Returns how the color was specified.
Definition: qcolor.h:88
void setCmyk(int c, int m, int y, int k, int a=255)
Sets the color to CMYK values, c (cyan), m (magenta), y (yellow), k (black), and a (alpha-channel...
Definition: qcolor.cpp:2243

◆ QColor() [9/9]

QColor::QColor ( int  x,
int  y,
int  z,
Spec  colorSpec 
)
private

Use one of the other QColor constructors, or one of the static convenience functions, instead.

Functions

◆ allowX11ColorNames()

bool QColor::allowX11ColorNames ( )
static

Returns true if setNamedColor() is allowed to look up colors in the X11 color database.

By default, this function returns false.

Note
This function is only available on the X11 platform.
See also
setAllowX11ColorNames()

Definition at line 2535 of file qcolor.cpp.

Referenced by qt_set_x11_resources(), setAllowX11ColorNames(), and setColorFromString().

2536 {
2538 }
static bool allowX11ColorNames
Definition: qcolor.cpp:55

◆ alpha()

int QColor::alpha ( ) const

Referenced by setBlue(), setGreen(), setRed(), and setRgb().

◆ alphaF()

qreal QColor::alphaF ( ) const

◆ black()

int QColor::black ( ) const

Referenced by lightnessF().

◆ blackF()

qreal QColor::blackF ( ) const

Returns the black color component of this color.

See also
black(), getCmykF(), {QColor::The CMYK Color Model}{The CMYK Color Model}

Definition at line 1624 of file qcolor.cpp.

Referenced by blackF(), and operator<<().

1625 {
1626  if (cspec != Invalid && cspec != Cmyk)
1627  return toCmyk().blackF();
1628  return ct.acmyk.black / qreal(USHRT_MAX);
1629 }
double qreal
Definition: qglobal.h:1193
QColor toCmyk() const
Creates and returns a CMYK QColor based on this color.
Definition: qcolor.cpp:1891
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
qreal blackF() const
Returns the black color component of this color.
Definition: qcolor.cpp:1624

◆ blue()

int QColor::blue ( ) const

Referenced by name(), setGreen(), and setRed().

◆ blueF()

qreal QColor::blueF ( ) const

◆ colorNames()

QStringList QColor::colorNames ( )
static

Returns a QStringList containing the color names Qt knows about.

See also
{QColor::Predefined Colors}{Predefined Colors}

Definition at line 632 of file qcolor.cpp.

633 {
634 #ifndef QT_NO_COLORNAMES
635  return qt_get_colornames();
636 #else
637  return QStringList();
638 #endif
639 }
QStringList qt_get_colornames()
Definition: qcolor_p.cpp:344
The QStringList class provides a list of strings.
Definition: qstringlist.h:66

◆ convertTo()

QColor QColor::convertTo ( QColor::Spec  colorSpec) const

Creates a copy of this color in the format specified by colorSpec.

See also
spec(), toCmyk(), toHsv(), toRgb(), isValid()

Definition at line 1927 of file qcolor.cpp.

Referenced by dark(), and light().

1928 {
1929  if (colorSpec == cspec)
1930  return *this;
1931  switch (colorSpec) {
1932  case Rgb:
1933  return toRgb();
1934  case Hsv:
1935  return toHsv();
1936  case Cmyk:
1937  return toCmyk();
1938  case Hsl:
1939  return toHsl();
1940  case Invalid:
1941  break;
1942  }
1943  return QColor(); // must be invalid
1944 }
QColor toCmyk() const
Creates and returns a CMYK QColor based on this color.
Definition: qcolor.cpp:1891
Spec cspec
Definition: qcolor.h:239
QColor toHsv() const
Creates and returns an HSV QColor based on this color.
Definition: qcolor.cpp:1783
QColor toRgb() const
Create and returns an RGB QColor based on this color.
Definition: qcolor.cpp:1636
QColor()
Constructs an invalid color with the RGB value (0, 0, 0).
Definition: qcolor.h:279
QColor toHsl() const
Creates and returns an HSL QColor based on this color.
Definition: qcolor.cpp:1834

◆ cyan()

int QColor::cyan ( ) const

Referenced by lightnessF().

◆ cyanF()

qreal QColor::cyanF ( ) const

Returns the cyan color component of this color.

See also
cyan(), getCmykF(), {QColor::The CMYK Color Model}{The CMYK Color Model}

Definition at line 1585 of file qcolor.cpp.

Referenced by cyanF(), and operator<<().

1586 {
1587  if (cspec != Invalid && cspec != Cmyk)
1588  return toCmyk().cyanF();
1589  return ct.acmyk.cyan / qreal(USHRT_MAX);
1590 }
qreal cyanF() const
Returns the cyan color component of this color.
Definition: qcolor.cpp:1585
double qreal
Definition: qglobal.h:1193
QColor toCmyk() const
Creates and returns a CMYK QColor based on this color.
Definition: qcolor.cpp:1891
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239

◆ dark()

QColor QColor::dark ( int  factor = 200) const

Use darker(factor) instead.

Definition at line 2447 of file qcolor.cpp.

Referenced by darker(), QWindowsCEStyle::drawComplexControl(), QWindowsMobileStyle::drawComplexControl(), QWindowsStyle::drawComplexControl(), QWindowsCEStyle::drawControl(), QWindowsStyle::drawControl(), QGtkStyle::drawPrimitive(), and qt_set_windows_color_resources().

2448 {
2449  if (factor <= 0) // invalid darkness factor
2450  return *this;
2451  else if (factor < 100) // makes color lighter
2452  return lighter(10000 / factor);
2453 
2454  QColor hsv = toHsv();
2455  hsv.ct.ahsv.value = (hsv.ct.ahsv.value * 100) / factor;
2456 
2457  // convert back to same color spec as original color
2458  return hsv.convertTo(cspec);
2459 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
QColor toHsv() const
Creates and returns an HSV QColor based on this color.
Definition: qcolor.cpp:1783
struct QColor::@220::@222 ahsv
QColor convertTo(Spec colorSpec) const
Creates a copy of this color in the format specified by colorSpec.
Definition: qcolor.cpp:1927
QColor lighter(int f=150) const
Returns a lighter (or darker) color, but does not change this object.
Definition: qcolor.h:298

◆ darker()

QColor QColor::darker ( int  factor = 200) const
inline

Returns a darker (or lighter) color, but does not change this object.

Since
4.3

If the factor is greater than 100, this functions returns a darker color. Setting factor to 300 returns a color that has one-third the brightness. If the factor is less than 100, the return color is lighter, but we recommend using the lighter() function for this purpose. If the factor is 0 or negative, the return value is unspecified.

The function converts the current RGB color to HSV, divides the value (V) component by factor and converts the color back to RGB.

See also
lighter(), isValid()

Definition at line 301 of file qcolor.h.

Referenced by QRenderRule::configurePalette(), QDeclarativeEnginePrivate::darker(), QPlastiqueStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QWindowsVistaStyle::drawControl(), QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QWindowsXPStyle::drawControl(), QMacStyle::drawControl(), QStyleHelper::drawDial(), QWindowsVistaStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), QCleanlooksStyle::drawPrimitive(), QGtkStyle::drawPrimitive(), QMacStyle::drawPrimitive(), light(), QWindowsXPStyle::polish(), QMotifStyle::polish(), QWindowsVistaStyle::polish(), qBrushDark(), qt_cleanlooks_draw_buttongradient(), qt_cleanlooks_draw_mdibutton(), qt_plastique_draw_handle(), qt_plastique_drawFrame(), qt_plastique_drawShadedPanel(), qt_set_windows_color_resources(), QCleanlooksStyle::standardPalette(), QCDEStyle::standardPalette(), QGtkStyle::standardPalette(), QPlastiqueStyle::standardPalette(), QStyle::standardPalette(), QWindowsVistaStyle::styleHint(), and QCleanlooksStyle::styleHint().

302 { return dark(f); }
QColor dark(int f=200) const
Use darker(factor) instead.
Definition: qcolor.cpp:2447

◆ fromCmyk()

QColor QColor::fromCmyk ( int  c,
int  m,
int  y,
int  k,
int  a = 255 
)
static

Static convenience function that returns a QColor constructed from the given CMYK color values: c (cyan), m (magenta), y (yellow), k (black), and a (alpha-channel, i.e.

transparency).

All the values must be in the range 0-255.

See also
toCmyk(), fromCmykF(), isValid(), {QColor::The CMYK Color Model}{The CMYK Color Model}

Definition at line 2305 of file qcolor.cpp.

2306 {
2307  if (c < 0 || c > 255
2308  || m < 0 || m > 255
2309  || y < 0 || y > 255
2310  || k < 0 || k > 255
2311  || a < 0 || a > 255) {
2312  qWarning("QColor::fromCmyk: CMYK parameters out of range");
2313  return QColor();
2314  }
2315 
2316  QColor color;
2317  color.cspec = Cmyk;
2318  color.ct.acmyk.alpha = a * 0x101;
2319  color.ct.acmyk.cyan = c * 0x101;
2320  color.ct.acmyk.magenta = m * 0x101;
2321  color.ct.acmyk.yellow = y * 0x101;
2322  color.ct.acmyk.black = k * 0x101;
2323  return color;
2324 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
unsigned char c[8]
Definition: qnumeric_p.h:62
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a
Q_CORE_EXPORT void qWarning(const char *,...)
QColor()
Constructs an invalid color with the RGB value (0, 0, 0).
Definition: qcolor.h:279
struct QColor::@220::@223 acmyk

◆ fromCmykF()

QColor QColor::fromCmykF ( qreal  c,
qreal  m,
qreal  y,
qreal  k,
qreal  a = 1.0 
)
static

Static convenience function that returns a QColor constructed from the given CMYK color values: c (cyan), m (magenta), y (yellow), k (black), and a (alpha-channel, i.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

e. transparency).

All the values must be in the range 0.0-1.0.

\sa toCmyk(), fromCmyk(), isValid(), {QColor#The CMYK Color
Model}{The CMYK Color Model}

Definition at line 2341 of file qcolor.cpp.

2342 {
2343  if (c < qreal(0.0) || c > qreal(1.0)
2344  || m < qreal(0.0) || m > qreal(1.0)
2345  || y < qreal(0.0) || y > qreal(1.0)
2346  || k < qreal(0.0) || k > qreal(1.0)
2347  || a < qreal(0.0) || a > qreal(1.0)) {
2348  qWarning("QColor::fromCmykF: CMYK parameters out of range");
2349  return QColor();
2350  }
2351 
2352  QColor color;
2353  color.cspec = Cmyk;
2354  color.ct.acmyk.alpha = qRound(a * USHRT_MAX);
2355  color.ct.acmyk.cyan = qRound(c * USHRT_MAX);
2356  color.ct.acmyk.magenta = qRound(m * USHRT_MAX);
2357  color.ct.acmyk.yellow = qRound(y * USHRT_MAX);
2358  color.ct.acmyk.black = qRound(k * USHRT_MAX);
2359  return color;
2360 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a
Q_CORE_EXPORT void qWarning(const char *,...)
QColor()
Constructs an invalid color with the RGB value (0, 0, 0).
Definition: qcolor.h:279
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
struct QColor::@220::@223 acmyk

◆ fromHsl()

QColor QColor::fromHsl ( int  h,
int  s,
int  l,
int  a = 255 
)
static

Static convenience function that returns a QColor constructed from the HSV color values, h (hue), s (saturation), l (lightness), and a (alpha-channel, i.

Since
4.6

e. transparency).

The value of \a s, \a l, and \a a must all be in the range 0-255; the value
of \a h must be in the range 0-359.

\sa toHsl(), fromHslF(), isValid()

Definition at line 2118 of file qcolor.cpp.

2119 {
2120  if (((h < 0 || h >= 360) && h != -1)
2121  || s < 0 || s > 255
2122  || l < 0 || l > 255
2123  || a < 0 || a > 255) {
2124  qWarning("QColor::fromHsv: HSV parameters out of range");
2125  return QColor();
2126  }
2127 
2128  QColor color;
2129  color.cspec = Hsl;
2130  color.ct.ahsl.alpha = a * 0x101;
2131  color.ct.ahsl.hue = h == -1 ? USHRT_MAX : (h % 360) * 100;
2132  color.ct.ahsl.saturation = s * 0x101;
2133  color.ct.ahsl.lightness = l * 0x101;
2134  color.ct.ahsl.pad = 0;
2135  return color;
2136 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
union QColor::@220 ct
struct QColor::@220::@224 ahsl
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a
Q_CORE_EXPORT void qWarning(const char *,...)
QFactoryLoader * l
QColor()
Constructs an invalid color with the RGB value (0, 0, 0).
Definition: qcolor.h:279

◆ fromHslF()

QColor QColor::fromHslF ( qreal  h,
qreal  s,
qreal  l,
qreal  a = 1.0 
)
static

Static convenience function that returns a QColor constructed from the HSV color values, h (hue), s (saturation), l (lightness), and a (alpha-channel, i.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.6

e. transparency).

All the values must be in the range 0.0-1.0.

\sa toHsl(), fromHsl(), isValid()

Definition at line 2153 of file qcolor.cpp.

Referenced by QDeclarativeEnginePrivate::hsla().

2154 {
2155  if (((h < qreal(0.0) || h > qreal(1.0)) && h != qreal(-1.0))
2156  || (s < qreal(0.0) || s > qreal(1.0))
2157  || (l < qreal(0.0) || l > qreal(1.0))
2158  || (a < qreal(0.0) || a > qreal(1.0))) {
2159  qWarning("QColor::fromHsvF: HSV parameters out of range");
2160  return QColor();
2161  }
2162 
2163  QColor color;
2164  color.cspec = Hsl;
2165  color.ct.ahsl.alpha = qRound(a * USHRT_MAX);
2166  color.ct.ahsl.hue = (h == qreal(-1.0)) ? USHRT_MAX : qRound(h * 36000);
2167  if (color.ct.ahsl.hue == 36000)
2168  color.ct.ahsl.hue = 0;
2169  color.ct.ahsl.saturation = qRound(s * USHRT_MAX);
2170  color.ct.ahsl.lightness = qRound(l * USHRT_MAX);
2171  color.ct.ahsl.pad = 0;
2172  return color;
2173 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double qreal
Definition: qglobal.h:1193
union QColor::@220 ct
struct QColor::@220::@224 ahsl
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a
Q_CORE_EXPORT void qWarning(const char *,...)
QFactoryLoader * l
QColor()
Constructs an invalid color with the RGB value (0, 0, 0).
Definition: qcolor.h:279
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ fromHsv()

QColor QColor::fromHsv ( int  h,
int  s,
int  v,
int  a = 255 
)
static

Static convenience function that returns a QColor constructed from the HSV color values, h (hue), s (saturation), v (value), and a (alpha-channel, i.e.

transparency).

The value of s, v, and a must all be in the range 0-255; the value of h must be in the range 0-359.

See also
toHsv(), fromHsvF(), isValid(), {QColor::The HSV Color Model}{The HSV Color Model}

Definition at line 2048 of file qcolor.cpp.

Referenced by QGraphicsScenePrivate::draw(), and parseColorValue().

2049 {
2050  if (((h < 0 || h >= 360) && h != -1)
2051  || s < 0 || s > 255
2052  || v < 0 || v > 255
2053  || a < 0 || a > 255) {
2054  qWarning("QColor::fromHsv: HSV parameters out of range");
2055  return QColor();
2056  }
2057 
2058  QColor color;
2059  color.cspec = Hsv;
2060  color.ct.ahsv.alpha = a * 0x101;
2061  color.ct.ahsv.hue = h == -1 ? USHRT_MAX : (h % 360) * 100;
2062  color.ct.ahsv.saturation = s * 0x101;
2063  color.ct.ahsv.value = v * 0x101;
2064  color.ct.ahsv.pad = 0;
2065  return color;
2066 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a
struct QColor::@220::@222 ahsv
Q_CORE_EXPORT void qWarning(const char *,...)
QColor()
Constructs an invalid color with the RGB value (0, 0, 0).
Definition: qcolor.h:279

◆ fromHsvF()

QColor QColor::fromHsvF ( qreal  h,
qreal  s,
qreal  v,
qreal  a = 1.0 
)
static

Static convenience function that returns a QColor constructed from the HSV color values, h (hue), s (saturation), v (value), and a (alpha-channel, i.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

e. transparency).

All the values must be in the range 0.0-1.0.

\sa toHsv(), fromHsv(), isValid(), {QColor#The HSV Color
Model}{The HSV Color Model}

Definition at line 2083 of file qcolor.cpp.

2084 {
2085  if (((h < qreal(0.0) || h > qreal(1.0)) && h != qreal(-1.0))
2086  || (s < qreal(0.0) || s > qreal(1.0))
2087  || (v < qreal(0.0) || v > qreal(1.0))
2088  || (a < qreal(0.0) || a > qreal(1.0))) {
2089  qWarning("QColor::fromHsvF: HSV parameters out of range");
2090  return QColor();
2091  }
2092 
2093  QColor color;
2094  color.cspec = Hsv;
2095  color.ct.ahsv.alpha = qRound(a * USHRT_MAX);
2096  color.ct.ahsv.hue = h == qreal(-1.0) ? USHRT_MAX : qRound(h * 36000);
2097  color.ct.ahsv.saturation = qRound(s * USHRT_MAX);
2098  color.ct.ahsv.value = qRound(v * USHRT_MAX);
2099  color.ct.ahsv.pad = 0;
2100  return color;
2101 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double qreal
Definition: qglobal.h:1193
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a
struct QColor::@220::@222 ahsv
Q_CORE_EXPORT void qWarning(const char *,...)
QColor()
Constructs an invalid color with the RGB value (0, 0, 0).
Definition: qcolor.h:279
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ fromRgb() [1/2]

QColor QColor::fromRgb ( QRgb  rgb)
static

Static convenience function that returns a QColor constructed from the given QRgb value rgb.

The alpha component of rgb is ignored (i.e. it is automatically set to 255), use the fromRgba() function to include the alpha-channel specified by the given QRgb value.

See also
fromRgba(), fromRgbF(), toRgb(), isValid()

Definition at line 1958 of file qcolor.cpp.

Referenced by fromRgba(), parseColorValue(), QmlJSDebugger::ColorPickerTool::pickColor(), and QWindowsVistaStyle::polish().

1959 {
1960  return fromRgb(qRed(rgb), qGreen(rgb), qBlue(rgb));
1961 }
int qRed(QRgb rgb)
Returns the red component of the ARGB quadruplet rgb.
Definition: qrgb.h:57
static QColor fromRgb(QRgb rgb)
Static convenience function that returns a QColor constructed from the given QRgb value rgb...
Definition: qcolor.cpp:1958
int qGreen(QRgb rgb)
Returns the green component of the ARGB quadruplet rgb.
Definition: qrgb.h:60
int qBlue(QRgb rgb)
Returns the blue component of the ARGB quadruplet rgb.
Definition: qrgb.h:63
QRgb rgb() const
Returns the RGB value of the color.
Definition: qcolor.cpp:1051

◆ fromRgb() [2/2]

QColor QColor::fromRgb ( int  r,
int  g,
int  b,
int  a = 255 
)
static

Static convenience function that returns a QColor constructed from the RGB color values, r (red), g (green), b (blue), and a (alpha-channel, i.e.

transparency).

All the values must be in the range 0-255.

See also
toRgb(), fromRgbF(), isValid()

Definition at line 1988 of file qcolor.cpp.

1989 {
1990  if (r < 0 || r > 255
1991  || g < 0 || g > 255
1992  || b < 0 || b > 255
1993  || a < 0 || a > 255) {
1994  qWarning("QColor::fromRgb: RGB parameters out of range");
1995  return QColor();
1996  }
1997 
1998  QColor color;
1999  color.cspec = Rgb;
2000  color.ct.argb.alpha = a * 0x101;
2001  color.ct.argb.red = r * 0x101;
2002  color.ct.argb.green = g * 0x101;
2003  color.ct.argb.blue = b * 0x101;
2004  color.ct.argb.pad = 0;
2005  return color;
2006 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a
struct QColor::@220::@221 argb
Q_CORE_EXPORT void qWarning(const char *,...)
QColor()
Constructs an invalid color with the RGB value (0, 0, 0).
Definition: qcolor.h:279

◆ fromRgba()

QColor QColor::fromRgba ( QRgb  rgba)
static

Static convenience function that returns a QColor constructed from the given QRgb value rgba.

Unlike the fromRgb() function, the alpha-channel specified by the given QRgb value is included.

See also
fromRgb(), isValid()

Definition at line 1974 of file qcolor.cpp.

Referenced by QSvgPaintEngine::saveGradientStops().

1975 {
1976  return fromRgb(qRed(rgba), qGreen(rgba), qBlue(rgba), qAlpha(rgba));
1977 }
int qRed(QRgb rgb)
Returns the red component of the ARGB quadruplet rgb.
Definition: qrgb.h:57
int qAlpha(QRgb rgba)
Returns the alpha component of the ARGB quadruplet rgba.
Definition: qrgb.h:66
static QColor fromRgb(QRgb rgb)
Static convenience function that returns a QColor constructed from the given QRgb value rgb...
Definition: qcolor.cpp:1958
QRgb rgba() const
Returns the RGB value of the color, including its alpha.
Definition: qcolor.cpp:1019
int qGreen(QRgb rgb)
Returns the green component of the ARGB quadruplet rgb.
Definition: qrgb.h:60
int qBlue(QRgb rgb)
Returns the blue component of the ARGB quadruplet rgb.
Definition: qrgb.h:63

◆ fromRgbF()

QColor QColor::fromRgbF ( qreal  r,
qreal  g,
qreal  b,
qreal  a = 1.0 
)
static

Static convenience function that returns a QColor constructed from the RGB color values, r (red), g (green), b (blue), and a (alpha-channel, i.e.

transparency).

All the values must be in the range 0.0-1.0.

See also
fromRgb(), toRgb(), isValid()

Definition at line 2017 of file qcolor.cpp.

Referenced by QGL2PaintEngineExPrivate::drawCachedGlyphs(), query_colormap(), and QDeclarativeEnginePrivate::rgba().

2018 {
2019  if (r < qreal(0.0) || r > qreal(1.0)
2020  || g < qreal(0.0) || g > qreal(1.0)
2021  || b < qreal(0.0) || b > qreal(1.0)
2022  || a < qreal(0.0) || a > qreal(1.0)) {
2023  qWarning("QColor::fromRgbF: RGB parameters out of range");
2024  return QColor();
2025  }
2026 
2027  QColor color;
2028  color.cspec = Rgb;
2029  color.ct.argb.alpha = qRound(a * USHRT_MAX);
2030  color.ct.argb.red = qRound(r * USHRT_MAX);
2031  color.ct.argb.green = qRound(g * USHRT_MAX);
2032  color.ct.argb.blue = qRound(b * USHRT_MAX);
2033  color.ct.argb.pad = 0;
2034  return color;
2035 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double qreal
Definition: qglobal.h:1193
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a
struct QColor::@220::@221 argb
Q_CORE_EXPORT void qWarning(const char *,...)
QColor()
Constructs an invalid color with the RGB value (0, 0, 0).
Definition: qcolor.h:279
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ getCmyk()

void QColor::getCmyk ( int *  c,
int *  m,
int *  y,
int *  k,
int *  a = 0 
)

Sets the contents pointed to by c, m, y, k, and a, to the cyan, magenta, yellow, black, and alpha-channel (transparency) components of the color's CMYK value.

These components can be retrieved individually using the cyan(), magenta(), yellow(), black() and alpha() functions.

See also
setCmyk(), {QColor::The CMYK Color Model}{The CMYK Color Model}

Definition at line 2186 of file qcolor.cpp.

Referenced by getCmyk().

2187 {
2188  if (!c || !m || !y || !k)
2189  return;
2190 
2191  if (cspec != Invalid && cspec != Cmyk) {
2192  toCmyk().getCmyk(c, m, y, k, a);
2193  return;
2194  }
2195 
2196  *c = ct.acmyk.cyan >> 8;
2197  *m = ct.acmyk.magenta >> 8;
2198  *y = ct.acmyk.yellow >> 8;
2199  *k = ct.acmyk.black >> 8;
2200 
2201  if (a)
2202  *a = ct.acmyk.alpha >> 8;
2203 }
unsigned char c[8]
Definition: qnumeric_p.h:62
QColor toCmyk() const
Creates and returns a CMYK QColor based on this color.
Definition: qcolor.cpp:1891
union QColor::@220 ct
void getCmyk(int *c, int *m, int *y, int *k, int *a=0)
Sets the contents pointed to by c, m, y, k, and a, to the cyan, magenta, yellow, black, and alpha-channel (transparency) components of the color&#39;s CMYK value.
Definition: qcolor.cpp:2186
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a

◆ getCmykF()

void QColor::getCmykF ( qreal c,
qreal m,
qreal y,
qreal k,
qreal a = 0 
)

Sets the contents pointed to by c, m, y, k, and a, to the cyan, magenta, yellow, black, and alpha-channel (transparency) components of the color's CMYK value.

These components can be retrieved individually using the cyanF(), magentaF(), yellowF(), blackF() and alphaF() functions.

See also
setCmykF(), {QColor::The CMYK Color Model}{The CMYK Color Model}

Definition at line 2215 of file qcolor.cpp.

Referenced by getCmykF().

2216 {
2217  if (!c || !m || !y || !k)
2218  return;
2219 
2220  if (cspec != Invalid && cspec != Cmyk) {
2221  toCmyk().getCmykF(c, m, y, k, a);
2222  return;
2223  }
2224 
2225  *c = ct.acmyk.cyan / qreal(USHRT_MAX);
2226  *m = ct.acmyk.magenta / qreal(USHRT_MAX);
2227  *y = ct.acmyk.yellow / qreal(USHRT_MAX);
2228  *k = ct.acmyk.black / qreal(USHRT_MAX);
2229 
2230  if (a)
2231  *a = ct.acmyk.alpha / qreal(USHRT_MAX);
2232 }
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
QColor toCmyk() const
Creates and returns a CMYK QColor based on this color.
Definition: qcolor.cpp:1891
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a
void getCmykF(qreal *c, qreal *m, qreal *y, qreal *k, qreal *a=0)
Sets the contents pointed to by c, m, y, k, and a, to the cyan, magenta, yellow, black, and alpha-channel (transparency) components of the color&#39;s CMYK value.
Definition: qcolor.cpp:2215

◆ getHsl()

void QColor::getHsl ( int *  h,
int *  s,
int *  l,
int *  a = 0 
) const

Sets the contents pointed to by h, s, l, and a, to the hue, saturation, lightness, and alpha-channel (transparency) components of the color's HSL value.

Since
4.6

These components can be retrieved individually using the hueHsl(), saturationHsl(), lightness() and alpha() functions.

See also
setHsl()

Definition at line 798 of file qcolor.cpp.

Referenced by getHsl().

799 {
800  if (!h || !s || !l)
801  return;
802 
803  if (cspec != Invalid && cspec != Hsl) {
804  toHsl().getHsl(h, s, l, a);
805  return;
806  }
807 
808  *h = ct.ahsl.hue == USHRT_MAX ? -1 : ct.ahsl.hue / 100;
809  *s = ct.ahsl.saturation >> 8;
810  *l = ct.ahsl.lightness >> 8;
811 
812  if (a)
813  *a = ct.ahsl.alpha >> 8;
814 }
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a
void getHsl(int *h, int *s, int *l, int *a=0) const
Sets the contents pointed to by h, s, l, and a, to the hue, saturation, lightness, and alpha-channel (transparency) components of the color&#39;s HSL value.
Definition: qcolor.cpp:798
QFactoryLoader * l
QColor toHsl() const
Creates and returns an HSL QColor based on this color.
Definition: qcolor.cpp:1834

◆ getHslF()

void QColor::getHslF ( qreal h,
qreal s,
qreal l,
qreal a = 0 
) const

Sets the contents pointed to by h, s, l, and a, to the hue, saturation, lightness, and alpha-channel (transparency) components of the color's HSL value.

Since
4.6

These components can be retrieved individually using the hueHslF(), saturationHslF(), lightnessF() and alphaF() functions.

See also
setHsl()

Definition at line 765 of file qcolor.cpp.

Referenced by getHslF().

766 {
767  if (!h || !s || !l)
768  return;
769 
770  if (cspec != Invalid && cspec != Hsl) {
771  toHsl().getHslF(h, s, l, a);
772  return;
773  }
774 
775  *h = ct.ahsl.hue == USHRT_MAX ? qreal(-1.0) : ct.ahsl.hue / qreal(36000.0);
776  *s = ct.ahsl.saturation / qreal(USHRT_MAX);
777  *l = ct.ahsl.lightness / qreal(USHRT_MAX);
778 
779  if (a)
780  *a = ct.ahsl.alpha / qreal(USHRT_MAX);
781 }
double qreal
Definition: qglobal.h:1193
union QColor::@220 ct
struct QColor::@220::@224 ahsl
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a
QFactoryLoader * l
int hue() const
QColor toHsl() const
Creates and returns an HSL QColor based on this color.
Definition: qcolor.cpp:1834
void getHslF(qreal *h, qreal *s, qreal *l, qreal *a=0) const
Sets the contents pointed to by h, s, l, and a, to the hue, saturation, lightness, and alpha-channel (transparency) components of the color&#39;s HSL value.
Definition: qcolor.cpp:765

◆ getHsv()

void QColor::getHsv ( int *  h,
int *  s,
int *  v,
int *  a = 0 
) const

Sets the contents pointed to by h, s, v, and a, to the hue, saturation, value, and alpha-channel (transparency) components of the color's HSV value.

These components can be retrieved individually using the hue(), saturation(), value() and alpha() functions.

See also
setHsv(), {QColor::The HSV Color Model}{The HSV Color Model}

Definition at line 679 of file qcolor.cpp.

Referenced by darkenPixmap(), QCommonStyle::drawPrimitive(), getHsv(), QPalette::QPalette(), qt_palette_from_color(), and rgb2hsv().

680 {
681  if (!h || !s || !v)
682  return;
683 
684  if (cspec != Invalid && cspec != Hsv) {
685  toHsv().getHsv(h, s, v, a);
686  return;
687  }
688 
689  *h = ct.ahsv.hue == USHRT_MAX ? -1 : ct.ahsv.hue / 100;
690  *s = ct.ahsv.saturation >> 8;
691  *v = ct.ahsv.value >> 8;
692 
693  if (a)
694  *a = ct.ahsv.alpha >> 8;
695 }
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a
QColor toHsv() const
Creates and returns an HSV QColor based on this color.
Definition: qcolor.cpp:1783
void getHsv(int *h, int *s, int *v, int *a=0) const
Sets the contents pointed to by h, s, v, and a, to the hue, saturation, value, and alpha-channel (tra...
Definition: qcolor.cpp:679

◆ getHsvF()

void QColor::getHsvF ( qreal h,
qreal s,
qreal v,
qreal a = 0 
) const

Sets the contents pointed to by h, s, v, and a, to the hue, saturation, value, and alpha-channel (transparency) components of the color's HSV value.

These components can be retrieved individually using the hueF(), saturationF(), valueF() and alphaF() functions.

See also
setHsv() {QColor::The HSV Color Model}{The HSV Color Model}

Definition at line 651 of file qcolor.cpp.

Referenced by getHsvF().

652 {
653  if (!h || !s || !v)
654  return;
655 
656  if (cspec != Invalid && cspec != Hsv) {
657  toHsv().getHsvF(h, s, v, a);
658  return;
659  }
660 
661  *h = ct.ahsv.hue == USHRT_MAX ? qreal(-1.0) : ct.ahsv.hue / qreal(36000.0);
662  *s = ct.ahsv.saturation / qreal(USHRT_MAX);
663  *v = ct.ahsv.value / qreal(USHRT_MAX);
664 
665  if (a)
666  *a = ct.ahsv.alpha / qreal(USHRT_MAX);
667 }
double qreal
Definition: qglobal.h:1193
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a
QColor toHsv() const
Creates and returns an HSV QColor based on this color.
Definition: qcolor.cpp:1783
struct QColor::@220::@222 ahsv
void getHsvF(qreal *h, qreal *s, qreal *v, qreal *a=0) const
Sets the contents pointed to by h, s, v, and a, to the hue, saturation, value, and alpha-channel (tra...
Definition: qcolor.cpp:651
int hue() const

◆ getRgb()

void QColor::getRgb ( int *  r,
int *  g,
int *  b,
int *  a = 0 
) const

Sets the contents pointed to by r, g, b, and a, to the red, green, blue, and alpha-channel (transparency) components of the color's RGB value.

These components can be retrieved individually using the red(), green(), blue() and alpha() functions.

See also
rgb(), setRgb()

Definition at line 916 of file qcolor.cpp.

Referenced by getRgb().

917 {
918  if (!r || !g || !b)
919  return;
920 
921  if (cspec != Invalid && cspec != Rgb) {
922  toRgb().getRgb(r, g, b, a);
923  return;
924  }
925 
926  *r = ct.argb.red >> 8;
927  *g = ct.argb.green >> 8;
928  *b = ct.argb.blue >> 8;
929 
930  if (a)
931  *a = ct.argb.alpha >> 8;
932 }
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a
QColor toRgb() const
Create and returns an RGB QColor based on this color.
Definition: qcolor.cpp:1636
void getRgb(int *r, int *g, int *b, int *a=0) const
Sets the contents pointed to by r, g, b, and a, to the red, green, blue, and alpha-channel (transpare...
Definition: qcolor.cpp:916

◆ getRgbF()

void QColor::getRgbF ( qreal r,
qreal g,
qreal b,
qreal a = 0 
) const

Sets the contents pointed to by r, g, b, and a, to the red, green, blue, and alpha-channel (transparency) components of the color's RGB value.

These components can be retrieved individually using the redF(), greenF(), blueF() and alphaF() functions.

See also
rgb(), setRgb()

Definition at line 887 of file qcolor.cpp.

Referenced by getRgbF().

888 {
889  if (!r || !g || !b)
890  return;
891 
892  if (cspec != Invalid && cspec != Rgb) {
893  toRgb().getRgbF(r, g, b, a);
894  return;
895  }
896 
897  *r = ct.argb.red / qreal(USHRT_MAX);
898  *g = ct.argb.green / qreal(USHRT_MAX);
899  *b = ct.argb.blue / qreal(USHRT_MAX);
900 
901  if (a)
902  *a = ct.argb.alpha / qreal(USHRT_MAX);
903 
904 }
double qreal
Definition: qglobal.h:1193
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a
void getRgbF(qreal *r, qreal *g, qreal *b, qreal *a=0) const
Sets the contents pointed to by r, g, b, and a, to the red, green, blue, and alpha-channel (transpare...
Definition: qcolor.cpp:887
QColor toRgb() const
Create and returns an RGB QColor based on this color.
Definition: qcolor.cpp:1636

◆ green()

int QColor::green ( ) const

Referenced by name(), setBlue(), and setRed().

◆ greenF()

qreal QColor::greenF ( ) const

◆ hslHue()

int QColor::hslHue ( ) const

Returns the hue color component of this color.

Since
4.6
See also
getHslF(), getHsl()

Definition at line 1433 of file qcolor.cpp.

Referenced by hslHue().

1434 {
1435  if (cspec != Invalid && cspec != Hsl)
1436  return toHsl().hslHue();
1437  return ct.ahsl.hue == USHRT_MAX ? -1 : ct.ahsl.hue / 100;
1438 }
union QColor::@220 ct
int hslHue() const
Returns the hue color component of this color.
Definition: qcolor.cpp:1433
Spec cspec
Definition: qcolor.h:239
QColor toHsl() const
Creates and returns an HSL QColor based on this color.
Definition: qcolor.cpp:1834

◆ hslHueF()

qreal QColor::hslHueF ( ) const

Returns the hue color component of this color.

Since
4.6
See also
hue(), getHslF()

Definition at line 1485 of file qcolor.cpp.

Referenced by hslHueF(), and operator<<().

1486 {
1487  if (cspec != Invalid && cspec != Hsl)
1488  return toHsl().hslHueF();
1489  return ct.ahsl.hue == USHRT_MAX ? qreal(-1.0) : ct.ahsl.hue / qreal(36000.0);
1490 }
double qreal
Definition: qglobal.h:1193
qreal hslHueF() const
Returns the hue color component of this color.
Definition: qcolor.cpp:1485
union QColor::@220 ct
struct QColor::@220::@224 ahsl
Spec cspec
Definition: qcolor.h:239
int hue() const
QColor toHsl() const
Creates and returns an HSL QColor based on this color.
Definition: qcolor.cpp:1834

◆ hslSaturation()

int QColor::hslSaturation ( ) const

Returns the saturation color component of this color.

Since
4.6
See also
saturationF(), getHsv(), {QColor::The HSV Color Model}{The HSV Color Model}

Definition at line 1451 of file qcolor.cpp.

Referenced by hslSaturation().

1452 {
1453  if (cspec != Invalid && cspec != Hsl)
1454  return toHsl().hslSaturation();
1455  return ct.ahsl.saturation >> 8;
1456 }
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
int hslSaturation() const
Returns the saturation color component of this color.
Definition: qcolor.cpp:1451
QColor toHsl() const
Creates and returns an HSL QColor based on this color.
Definition: qcolor.cpp:1834

◆ hslSaturationF()

qreal QColor::hslSaturationF ( ) const

Returns the saturation color component of this color.

Since
4.6
See also
saturationF() getHslF()

Definition at line 1502 of file qcolor.cpp.

Referenced by hslSaturationF(), and operator<<().

1503 {
1504  if (cspec != Invalid && cspec != Hsl)
1505  return toHsl().hslSaturationF();
1506  return ct.ahsl.saturation / qreal(USHRT_MAX);
1507 }
double qreal
Definition: qglobal.h:1193
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
qreal hslSaturationF() const
Returns the saturation color component of this color.
Definition: qcolor.cpp:1502
QColor toHsl() const
Creates and returns an HSL QColor based on this color.
Definition: qcolor.cpp:1834

◆ hsvHue()

int QColor::hsvHue ( ) const

Returns the hue color component of this color.

See also
hueF(), getHsv(), {QColor::The HSV Color Model}{The HSV Color Model}

Definition at line 1311 of file qcolor.cpp.

Referenced by setBlueF().

1312 {
1313  if (cspec != Invalid && cspec != Hsv)
1314  return toHsv().hue();
1315  return ct.ahsv.hue == USHRT_MAX ? -1 : ct.ahsv.hue / 100;
1316 }
union QColor::@220 ct
ushort hue
Returns the hue color component of this color.
Definition: qcolor.h:250
Spec cspec
Definition: qcolor.h:239
QColor toHsv() const
Creates and returns an HSV QColor based on this color.
Definition: qcolor.cpp:1783

◆ hsvHueF()

qreal QColor::hsvHueF ( ) const

Returns the hue color component of this color.

See also
hue(), getHsvF(), {QColor::The HSV Color Model}{The HSV Color Model}

Definition at line 1377 of file qcolor.cpp.

Referenced by hueF().

1378 {
1379  if (cspec != Invalid && cspec != Hsv)
1380  return toHsv().hueF();
1381  return ct.ahsv.hue == USHRT_MAX ? qreal(-1.0) : ct.ahsv.hue / qreal(36000.0);
1382 }
double qreal
Definition: qglobal.h:1193
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
QColor toHsv() const
Creates and returns an HSV QColor based on this color.
Definition: qcolor.cpp:1783
struct QColor::@220::@222 ahsv
qreal hueF() const
Returns the hue color component of this color.
Definition: qcolor.cpp:1366
int hue() const

◆ hsvSaturation()

int QColor::hsvSaturation ( ) const

Returns the saturation color component of this color.

See also
saturationF(), getHsv(), {QColor::The HSV Color Model}{The HSV Color Model}

Definition at line 1338 of file qcolor.cpp.

Referenced by hsvHue().

1339 {
1340  if (cspec != Invalid && cspec != Hsv)
1341  return toHsv().saturation();
1342  return ct.ahsv.saturation >> 8;
1343 }
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
QColor toHsv() const
Creates and returns an HSV QColor based on this color.
Definition: qcolor.cpp:1783
ushort saturation
Returns the saturation color component of this color.
Definition: qcolor.h:251

◆ hsvSaturationF()

qreal QColor::hsvSaturationF ( ) const

Returns the saturation color component of this color.

See also
saturation() getHsvF(), {QColor::The HSV Color Model}{The HSV Color Model}

Definition at line 1403 of file qcolor.cpp.

Referenced by saturationF().

1404 {
1405  if (cspec != Invalid && cspec != Hsv)
1406  return toHsv().saturationF();
1407  return ct.ahsv.saturation / qreal(USHRT_MAX);
1408 }
double qreal
Definition: qglobal.h:1193
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
qreal saturationF() const
Returns the saturation color component of this color.
Definition: qcolor.cpp:1392
QColor toHsv() const
Creates and returns an HSV QColor based on this color.
Definition: qcolor.cpp:1783

◆ hue()

int QColor::hue ( ) const

Referenced by setBlueF(), toHsl(), and toHsv().

◆ hueF()

qreal QColor::hueF ( ) const

Returns the hue color component of this color.

The color is implicitly converted to HSV.

See also
hsvHueF(), hue(), getHsvF(), {QColor::The HSV Color Model}{The HSV Color Model}

Definition at line 1366 of file qcolor.cpp.

Referenced by hsvHueF(), and operator<<().

1367 {
1368  return hsvHueF();
1369 }
qreal hsvHueF() const
Returns the hue color component of this color.
Definition: qcolor.cpp:1377

◆ invalidate()

void QColor::invalidate ( )
private

Marks the color as invalid and sets all components to zero (alpha is set to fully opaque for compatibility with Qt 3).

Warning
This function is not part of the public interface.

Definition at line 2563 of file qcolor.cpp.

Referenced by operator>>(), QColor(), setColorFromString(), setHsl(), setHsv(), setRgb(), and setRgbF().

2564 {
2565  cspec = Invalid;
2566  ct.argb.alpha = USHRT_MAX;
2567  ct.argb.red = 0;
2568  ct.argb.green = 0;
2569  ct.argb.blue = 0;
2570  ct.argb.pad = 0;
2571 }
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239

◆ isValid()

bool QColor::isValid ( ) const
inline

◆ isValidColor()

bool QColor::isValidColor ( const QString name)
static

Returns true if the name is a valid color name and can be used to construct a valid QColor object, otherwise returns false.

Since
4.7

It uses the same algorithm used in setNamedColor().

See also
setNamedColor()

Definition at line 579 of file qcolor.cpp.

580 {
581  return !name.isEmpty() && QColor().setColorFromString(name);
582 }
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QColor()
Constructs an invalid color with the RGB value (0, 0, 0).
Definition: qcolor.h:279

◆ light()

QColor QColor::light ( int  factor = 150) const

Use lighter(factor) instead.

Definition at line 2391 of file qcolor.cpp.

Referenced by QWindowsStyle::drawComplexControl(), QWindowsCEStyle::drawControl(), QCleanlooksStyle::drawControl(), QWindowsStyle::drawControl(), lighter(), and qt_set_windows_color_resources().

2392 {
2393  if (factor <= 0) // invalid lightness factor
2394  return *this;
2395  else if (factor < 100) // makes color darker
2396  return darker(10000 / factor);
2397 
2398  QColor hsv = toHsv();
2399  int s = hsv.ct.ahsv.saturation;
2400  int v = hsv.ct.ahsv.value;
2401 
2402  v = (factor*v)/100;
2403  if (v > USHRT_MAX) {
2404  // overflow... adjust saturation
2405  s -= v - USHRT_MAX;
2406  if (s < 0)
2407  s = 0;
2408  v = USHRT_MAX;
2409  }
2410 
2411  hsv.ct.ahsv.saturation = s;
2412  hsv.ct.ahsv.value = v;
2413 
2414  // convert back to same color spec as original color
2415  return hsv.convertTo(cspec);
2416 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
QColor toHsv() const
Creates and returns an HSV QColor based on this color.
Definition: qcolor.cpp:1783
QColor darker(int f=200) const
Returns a darker (or lighter) color, but does not change this object.
Definition: qcolor.h:301
struct QColor::@220::@222 ahsv
QColor convertTo(Spec colorSpec) const
Creates a copy of this color in the format specified by colorSpec.
Definition: qcolor.cpp:1927

◆ lighter()

QColor QColor::lighter ( int  factor = 150) const
inline

Returns a lighter (or darker) color, but does not change this object.

Since
4.3

If the factor is greater than 100, this functions returns a lighter color. Setting factor to 150 returns a color that is 50% brighter. If the factor is less than 100, the return color is darker, but we recommend using the darker() function for this purpose. If the factor is 0 or negative, the return value is unspecified.

The function converts the current RGB color to HSV, multiplies the value (V) component by factor and converts the color back to RGB.

See also
darker(), isValid()

Definition at line 298 of file qcolor.h.

Referenced by QRenderRule::configurePalette(), dark(), QPlastiqueStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QPlastiqueStyle::drawControl(), QWindowsMobileStyle::drawControl(), QCleanlooksStyle::drawControl(), QGtkStyle::drawControl(), QMacStyle::drawControl(), QStyleHelper::drawDial(), QPlastiqueStyle::drawPrimitive(), QCleanlooksStyle::drawPrimitive(), QDeclarativeEnginePrivate::lighter(), QDecorationWindows::paint(), QDecorationWindows::paintButton(), QCleanlooksStyle::polish(), qBrushLight(), qDrawEdge(), qDrawRoundedCorners(), qt_cleanlooks_draw_buttongradient(), qt_plastique_drawFrame(), qt_plastique_drawShadedPanel(), qt_set_windows_color_resources(), QCleanlooksStyle::standardPalette(), QCDEStyle::standardPalette(), QGtkStyle::standardPalette(), QStyle::standardPalette(), QMotifStyle::standardPalette(), QWindowsMobileStyle::standardPixmap(), and QScriptEdit::updateExtraSelections().

299 { return light(f); }
QColor light(int f=150) const
Use lighter(factor) instead.
Definition: qcolor.cpp:2391

◆ lightness()

int QColor::lightness ( ) const

Referenced by hslSaturation(), and toHsl().

◆ lightnessF()

qreal QColor::lightnessF ( ) const

Returns the lightness color component of this color.

Since
4.6
See also
value() getHslF()

Definition at line 1519 of file qcolor.cpp.

Referenced by lightnessF(), and operator<<().

1520 {
1521  if (cspec != Invalid && cspec != Hsl)
1522  return toHsl().lightnessF();
1523  return ct.ahsl.lightness / qreal(USHRT_MAX);
1524 }
double qreal
Definition: qglobal.h:1193
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
qreal lightnessF() const
Returns the lightness color component of this color.
Definition: qcolor.cpp:1519
QColor toHsl() const
Creates and returns an HSL QColor based on this color.
Definition: qcolor.cpp:1834

◆ magenta()

int QColor::magenta ( ) const

Referenced by lightnessF().

◆ magentaF()

qreal QColor::magentaF ( ) const

Returns the magenta color component of this color.

See also
magenta(), getCmykF(), {QColor::The CMYK Color Model}{The CMYK Color Model}

Definition at line 1598 of file qcolor.cpp.

Referenced by magentaF(), and operator<<().

1599 {
1600  if (cspec != Invalid && cspec != Cmyk)
1601  return toCmyk().magentaF();
1602  return ct.acmyk.magenta / qreal(USHRT_MAX);
1603 }
double qreal
Definition: qglobal.h:1193
QColor toCmyk() const
Creates and returns a CMYK QColor based on this color.
Definition: qcolor.cpp:1891
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
qreal magentaF() const
Returns the magenta color component of this color.
Definition: qcolor.cpp:1598

◆ name()

QString QColor::name ( ) const

Returns the name of the color in the format "#RRGGBB"; i.e.

a "#" character followed by three two-digit hexadecimal numbers.

See also
setNamedColor()

Definition at line 529 of file qcolor.cpp.

Referenced by QmlJSDebugger::ToolBarColorBox::copyColorToClipboard(), QTextHtmlExporter::emitBackgroundAttribute(), QTextHtmlExporter::emitCharFormatStyle(), QTextHtmlExporter::emitFrameStyle(), generateWavyPixmap(), QmlJSDebugger::ToolBarColorBox::mouseMoveEvent(), QTextOdfWriter::writeBlockFormat(), and QTextOdfWriter::writeCharacterFormat().

530 {
531  QString s;
532  s.sprintf("#%02x%02x%02x", red(), green(), blue());
533  return s;
534 }
QString & sprintf(const char *format,...)
Safely builds a formatted string from the format string cformat and an arbitrary list of arguments...
Definition: qstring.cpp:5567
int red() const
int green() const
The QString class provides a Unicode character string.
Definition: qstring.h:83
int blue() const

◆ operator QVariant()

QColor::operator QVariant ( ) const

Returns the color as a QVariant.

Definition at line 2521 of file qcolor.cpp.

2522 {
2523  return QVariant(QVariant::Color, this);
2524 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92

◆ operator!=()

bool QColor::operator!= ( const QColor c) const

Returns true if this color has a different RGB and alpha values from color; otherwise returns false.

Definition at line 2514 of file qcolor.cpp.

2515 { return !operator==(color); }
bool operator==(const QColor &c) const
Returns true if this color has the same RGB and alpha values as color; otherwise returns false...
Definition: qcolor.cpp:2486

◆ operator=() [1/2]

QColor & QColor::operator= ( const QColor color)

Assigns a copy of color to this color, and returns a reference to it.

Definition at line 2464 of file qcolor.cpp.

Referenced by operator=().

2465 {
2466  cspec = color.cspec;
2467  ct.argb = color.ct.argb;
2468  return *this;
2469 }
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
struct QColor::@220::@221 argb

◆ operator=() [2/2]

QColor & QColor::operator= ( Qt::GlobalColor  color)

Assigns a copy of color and returns a reference to this color.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 2477 of file qcolor.cpp.

2478 {
2479  return operator=(QColor(color));
2480 }
QColor & operator=(const QColor &)
Assigns a copy of color to this color, and returns a reference to it.
Definition: qcolor.cpp:2464
QColor()
Constructs an invalid color with the RGB value (0, 0, 0).
Definition: qcolor.h:279

◆ operator==()

bool QColor::operator== ( const QColor c) const

Returns true if this color has the same RGB and alpha values as color; otherwise returns false.

Definition at line 2486 of file qcolor.cpp.

Referenced by operator!=().

2487 {
2488  if (cspec == Hsl && cspec == color.cspec) {
2489  return (ct.argb.alpha == color.ct.argb.alpha
2490  && ((((ct.ahsl.hue % 36000) == (color.ct.ahsl.hue % 36000)))
2491  || (ct.ahsl.hue == color.ct.ahsl.hue))
2492  && (qAbs(ct.ahsl.saturation - color.ct.ahsl.saturation) < 50
2493  || ct.ahsl.lightness == 0
2494  || color.ct.ahsl.lightness == 0
2495  || ct.ahsl.lightness == USHRT_MAX
2496  || color.ct.ahsl.lightness == USHRT_MAX)
2497  && (qAbs(ct.ahsl.lightness - color.ct.ahsl.lightness)) < 50);
2498  } else {
2499  return (cspec == color.cspec
2500  && ct.argb.alpha == color.ct.argb.alpha
2501  && (((cspec == QColor::Hsv)
2502  && ((ct.ahsv.hue % 36000) == (color.ct.ahsv.hue % 36000)))
2503  || (ct.ahsv.hue == color.ct.ahsv.hue))
2504  && ct.argb.green == color.ct.argb.green
2505  && ct.argb.blue == color.ct.argb.blue
2506  && ct.argb.pad == color.ct.argb.pad);
2507  }
2508 }
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201

◆ red()

int QColor::red ( ) const

Referenced by name(), setAlphaF(), setBlue(), and setGreen().

◆ redF()

qreal QColor::redF ( ) const

◆ rgb()

QColor::rgb ( ) const

Returns the RGB value of the color.

Use getRgb() instead.

The alpha value is opaque.

See also
getRgb(), rgba()

Definition at line 1051 of file qcolor.cpp.

Referenced by QGLGlyphCache::allocTexture(), QGLContext::choosePixelFormat(), QX11PixmapData::createBitmapFromImage(), darkenPixmap(), QWindowsMobileStylePrivate::drawScrollbarGroove(), QWin32PrintEngine::drawTextItem(), QColorWell::dropEvent(), QX11PixmapData::fill(), QBitmap::fromImage(), QWindowsMobileStyle::generatedIconPixmap(), QColorShower::hsvEd(), makeBitmapCompliantIfNeeded(), operator<<(), QColorLuminancePicker::paintEvent(), QmlJSDebugger::ColorPickerTool::pickColor(), QCleanlooksStyle::polish(), qt_transparent_pixel(), QColorPicker::resizeEvent(), rgb(), QColorDialogPrivate::selectColor(), QPainter::setBackground(), QPainter::setBrush(), setColorFromString(), QColorDialog::setCurrentColor(), QGLColormap::setEntry(), QColorShower::setHsv(), QPainter::setPen(), QAhiScreen::solidFill(), QMotifStyle::standardPixmap(), QCommonStyle::styleHint(), QWindowsVistaStyle::styleHint(), QCleanlooksStyle::styleHint(), QX11PixmapData::toImage(), and QX11PaintEngine::updatePen().

1052 {
1053  if (cspec != Invalid && cspec != Rgb)
1054  return toRgb().rgb();
1055  return qRgb(ct.argb.red >> 8, ct.argb.green >> 8, ct.argb.blue >> 8);
1056 }
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
QColor toRgb() const
Create and returns an RGB QColor based on this color.
Definition: qcolor.cpp:1636
QRgb qRgb(int r, int g, int b)
Returns the ARGB quadruplet (255, {r}, {g}, {b}).
Definition: qrgb.h:69
QRgb rgb() const
Returns the RGB value of the color.
Definition: qcolor.cpp:1051

◆ rgba()

QRgb QColor::rgba ( ) const

Returns the RGB value of the color, including its alpha.

For an invalid color, the alpha value of the returned color is unspecified.

See also
setRgba(), rgb()

Definition at line 1019 of file qcolor.cpp.

Referenced by QPdfEnginePrivate::addImage(), QGLPixmapData::bind(), QRasterBuffer::colorizeBitmap(), colorizeBitmap(), QImageData::create(), QPixmap::createMaskFromColor(), QPlastiqueStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QPlastiqueStyle::drawControl(), QWindowsMobileStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), QCleanlooksStyle::drawPrimitive(), QGtkStyle::drawPrimitive(), QBlittablePixmapData::fill(), QMacPixmapData::fill(), QRasterPixmapData::fill(), QX11PixmapData::fill(), QVGPixmapData::fill(), QGLPixmapData::fill(), QImage::fill(), QGLPixmapData::fillImage(), QWindowsMobileStyle::generatedIconPixmap(), QDeclarativeCompiler::genLiteralAssignment(), QColorDialog::getRgba(), hash(), QGLPixmapData::paintEngine(), QColormap::pixel(), qBrushDark(), qBrushLight(), qBrushSetAlphaF(), QRenderRule::QRenderRule(), qt_conv16ToRgb(), qt_plastique_draw_gradient(), qt_plastique_draw_handle(), QSvgIOHandler::read(), rgba(), QPSPrintEngine::setBrush(), QPdfEngine::setBrush(), QSpanData::setup(), QAhiScreen::solidFill(), solidFill_template(), QWindowsMobileStyle::standardPixmap(), QGtkStyle::standardPixmap(), QCommonStyle::styleHint(), QStyleSheetStyle::styleHint(), QX11PaintEngine::updateBrush(), and QX11PaintEngine::updatePen().

1020 {
1021  if (cspec != Invalid && cspec != Rgb)
1022  return toRgb().rgba();
1023  return qRgba(ct.argb.red >> 8, ct.argb.green >> 8, ct.argb.blue >> 8, ct.argb.alpha >> 8);
1024 }
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
QColor toRgb() const
Create and returns an RGB QColor based on this color.
Definition: qcolor.cpp:1636
QRgb rgba() const
Returns the RGB value of the color, including its alpha.
Definition: qcolor.cpp:1019
QRgb qRgba(int r, int g, int b, int a)
Returns the ARGB quadruplet ({a}, {r}, {g}, {b}).
Definition: qrgb.h:72

◆ saturation()

int QColor::saturation ( ) const

Referenced by hsvHue().

◆ saturationF()

qreal QColor::saturationF ( ) const

Returns the saturation color component of this color.

The color is implicitly converted to HSV.

See also
hsvSaturationF(), saturation() getHsvF(), {QColor::The HSV Color Model}{The HSV Color Model}

Definition at line 1392 of file qcolor.cpp.

Referenced by hsvSaturationF(), and operator<<().

1393 {
1394  return hsvSaturationF();
1395 }
qreal hsvSaturationF() const
Returns the saturation color component of this color.
Definition: qcolor.cpp:1403

◆ setAllowX11ColorNames()

void QColor::setAllowX11ColorNames ( bool  enabled)
static

Allow setNamedColor() to look up colors in the X11 color database if enabled.

By default, setNamedColor() does not look up colors in the X11 color database.

Note
This function is only available on the X11 platform.
See also
setNamedColor(), allowX11ColorNames()

Definition at line 2549 of file qcolor.cpp.

Referenced by qt_set_x11_resources().

2550 {
2552 }
static bool allowX11ColorNames()
Returns true if setNamedColor() is allowed to look up colors in the X11 color database.
Definition: qcolor.cpp:2535
#define enabled

◆ setAlpha()

void QColor::setAlpha ( int  alpha)

Sets the alpha of this color to alpha.

Integer alpha is specified in the range 0-255.

See also
alpha(), alphaF(), {QColor::Alpha-Blended Drawing}{Alpha-Blended Drawing}

Definition at line 1094 of file qcolor.cpp.

Referenced by QTextLine::draw(), QCleanlooksStyle::drawComplexControl(), QGtkStyle::drawComplexControl(), QPlastiqueStyle::drawControl(), QMacStyle::drawControl(), QStyleHelper::drawDial(), QPlastiqueStyle::drawPrimitive(), QCleanlooksStyle::drawPrimitive(), QWindowsMobileStyle::generatedIconPixmap(), QPagePreview::paintEvent(), QLineEdit::paintEvent(), qt_plastique_draw_handle(), QGtkStyle::standardPixmap(), QX11PaintEngine::updateBrush(), and QX11PaintEngine::updatePen().

1095 {
1096  QCOLOR_INT_RANGE_CHECK("QColor::setAlpha", alpha);
1097  ct.argb.alpha = alpha * 0x101;
1098 }
union QColor::@220 ct
int alpha() const
#define QCOLOR_INT_RANGE_CHECK(fn, var)
Definition: qcolor.cpp:281

◆ setAlphaF()

void QColor::setAlphaF ( qreal  alpha)

Sets the alpha of this color to alpha.

qreal alpha is specified in the range 0.0-1.0.

See also
alphaF(), alpha(), {QColor::Alpha-Blended Drawing}{Alpha-Blended Drawing}

Definition at line 1117 of file qcolor.cpp.

Referenced by constructColor(), QMacStyle::drawControl(), QStyleHelper::drawDial(), QMacStyle::drawPrimitive(), QWidgetPrivate::drawWidget(), QCommonStyle::generatedIconPixmap(), make_widget_eventUPP(), qBrushSetAlphaF(), qt_premultiplyColor(), QItemDelegate::selected(), and QVGPaintEnginePrivate::setBrush().

1118 {
1119  QCOLOR_REAL_RANGE_CHECK("QColor::setAlphaF", alpha);
1120  qreal tmp = alpha * USHRT_MAX;
1121  ct.argb.alpha = qRound(tmp);
1122 }
double qreal
Definition: qglobal.h:1193
union QColor::@220 ct
int alpha() const
#define QCOLOR_REAL_RANGE_CHECK(fn, var)
Definition: qcolor.cpp:289
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ setBlue()

void QColor::setBlue ( int  blue)

Sets the blue color component of this color to blue.

Integer components are specified in the range 0-255.

See also
blue(), blueF(), setRgb()

Definition at line 1199 of file qcolor.cpp.

Referenced by QCommandLinkButtonPrivate::mergedColors(), and mergedColors().

1200 {
1201  QCOLOR_INT_RANGE_CHECK("QColor::setBlue", blue);
1202  if (cspec != Rgb)
1203  setRgb(red(), green(), blue, alpha());
1204  else
1205  ct.argb.blue = blue * 0x101;
1206 }
void setRgb(int r, int g, int b, int a=255)
Sets the RGB value to r, g, b and the alpha value to a.
Definition: qcolor.cpp:980
union QColor::@220 ct
int red() const
int green() const
Spec cspec
Definition: qcolor.h:239
int alpha() const
int blue() const
#define QCOLOR_INT_RANGE_CHECK(fn, var)
Definition: qcolor.cpp:281

◆ setBlueF()

void QColor::setBlueF ( qreal  blue)

Sets the blue color component of this color to blue.

Float components are specified in the range 0.0-1.0.

See also
blueF(), blue(), setRgbF()

Definition at line 1282 of file qcolor.cpp.

Referenced by qt_premultiplyColor().

1283 {
1284  QCOLOR_REAL_RANGE_CHECK("QColor::setBlueF", blue);
1285  if (cspec != Rgb)
1286  setRgbF(redF(), greenF(), blue, alphaF());
1287  else
1288  ct.argb.blue = qRound(blue * USHRT_MAX);
1289 }
qreal alphaF() const
Returns the alpha color component of this color.
Definition: qcolor.cpp:1106
union QColor::@220 ct
qreal greenF() const
Returns the green color component of this color.
Definition: qcolor.cpp:1241
void setRgbF(qreal r, qreal g, qreal b, qreal a=1.0)
Sets the color channels of this color to r (red), g (green), b (blue) and a (alpha, transparency).
Definition: qcolor.cpp:954
Spec cspec
Definition: qcolor.h:239
qreal redF() const
Returns the red color component of this color.
Definition: qcolor.cpp:1213
int blue() const
#define QCOLOR_REAL_RANGE_CHECK(fn, var)
Definition: qcolor.cpp:289
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ setCmyk()

void QColor::setCmyk ( int  c,
int  m,
int  y,
int  k,
int  a = 255 
)

Sets the color to CMYK values, c (cyan), m (magenta), y (yellow), k (black), and a (alpha-channel, i.e.

transparency).

All the values must be in the range 0-255.

See also
getCmyk(), setCmykF(), {QColor::The CMYK Color Model}{The CMYK Color Model}

Definition at line 2243 of file qcolor.cpp.

Referenced by QColor().

2244 {
2245  if (c < 0 || c > 255
2246  || m < 0 || m > 255
2247  || y < 0 || y > 255
2248  || k < 0 || k > 255
2249  || a < 0 || a > 255) {
2250  qWarning("QColor::setCmyk: CMYK parameters out of range");
2251  return;
2252  }
2253 
2254  cspec = Cmyk;
2255  ct.acmyk.alpha = a * 0x101;
2256  ct.acmyk.cyan = c * 0x101;
2257  ct.acmyk.magenta = m * 0x101;
2258  ct.acmyk.yellow = y * 0x101;
2259  ct.acmyk.black = k * 0x101;
2260 }
unsigned char c[8]
Definition: qnumeric_p.h:62
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a
Q_CORE_EXPORT void qWarning(const char *,...)

◆ setCmykF()

void QColor::setCmykF ( qreal  c,
qreal  m,
qreal  y,
qreal  k,
qreal  a = 1.0 
)

Sets the color to CMYK values, c (cyan), m (magenta), y (yellow), k (black), and a (alpha-channel, i.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

e. transparency).

All the values must be in the range 0.0-1.0.

\sa getCmykF() setCmyk(), {QColor#The CMYK Color Model}{The CMYK
Color Model}

Definition at line 2276 of file qcolor.cpp.

Referenced by qcolorFromCGColor().

2277 {
2278  if (c < qreal(0.0) || c > qreal(1.0)
2279  || m < qreal(0.0) || m > qreal(1.0)
2280  || y < qreal(0.0) || y > qreal(1.0)
2281  || k < qreal(0.0) || k > qreal(1.0)
2282  || a < qreal(0.0) || a > qreal(1.0)) {
2283  qWarning("QColor::setCmykF: CMYK parameters out of range");
2284  return;
2285  }
2286 
2287  cspec = Cmyk;
2288  ct.acmyk.alpha = qRound(a * USHRT_MAX);
2289  ct.acmyk.cyan = qRound(c * USHRT_MAX);
2290  ct.acmyk.magenta = qRound(m * USHRT_MAX);
2291  ct.acmyk.yellow = qRound(y * USHRT_MAX);
2292  ct.acmyk.black = qRound(k * USHRT_MAX);
2293 }
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a
Q_CORE_EXPORT void qWarning(const char *,...)
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ setColorFromString()

bool QColor::setColorFromString ( const QString name)
private

Definition at line 584 of file qcolor.cpp.

Referenced by setNamedColor().

585 {
586  if (name.isEmpty()) {
587  invalidate();
588  return true;
589  }
590 
591  if (name.startsWith(QLatin1Char('#'))) {
592  QRgb rgb;
593  if (qt_get_hex_rgb(name.constData(), name.length(), &rgb)) {
594  setRgb(rgb);
595  return true;
596  } else {
597  invalidate();
598  return false;
599  }
600  }
601 
602 #ifndef QT_NO_COLORNAMES
603  QRgb rgb;
604  if (qt_get_named_rgb(name.constData(), name.length(), &rgb)) {
605  setRgba(rgb);
606  return true;
607  } else
608 #endif
609  {
610 #ifdef Q_WS_X11
611  XColor result;
612  if (allowX11ColorNames()
614  && QX11Info::display()
615  && XParseColor(QX11Info::display(), QX11Info::appColormap(), name.toLatin1().constData(), &result)) {
616  setRgb(result.red >> 8, result.green >> 8, result.blue >> 8);
617  return true;
618  } else
619 #endif
620  {
621  invalidate();
622  return false;
623  }
624  }
625 }
void setRgb(int r, int g, int b, int a=255)
Sets the RGB value to r, g, b and the alpha value to a.
Definition: qcolor.cpp:980
unsigned int QRgb
Definition: qrgb.h:53
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
void invalidate()
Marks the color as invalid and sets all components to zero (alpha is set to fully opaque for compatib...
Definition: qcolor.cpp:2563
bool qt_get_named_rgb(const char *name, QRgb *rgb)
Definition: qcolor_p.cpp:306
static bool allowX11ColorNames()
Returns true if setNamedColor() is allowed to look up colors in the X11 color database.
Definition: qcolor.cpp:2535
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
static Qt::HANDLE appColormap(int screen=-1)
Returns a handle for the application&#39;s color map on the given screen.
void setRgba(QRgb rgba)
Use setRgb() instead.
Definition: qcolor.cpp:1031
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
bool qt_get_hex_rgb(const char *name, QRgb *rgb)
Definition: qcolor_p.cpp:76
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712
QRgb rgb() const
Returns the RGB value of the color.
Definition: qcolor.cpp:1051
static Display * display()
Returns the default display for the application.

◆ setGreen()

void QColor::setGreen ( int  green)

Sets the green color component of this color to green.

Integer components are specified in the range 0-255.

See also
green(), greenF(), setRgb()

Definition at line 1170 of file qcolor.cpp.

Referenced by QCommandLinkButtonPrivate::mergedColors(), and mergedColors().

1171 {
1172  QCOLOR_INT_RANGE_CHECK("QColor::setGreen", green);
1173  if (cspec != Rgb)
1174  setRgb(red(), green, blue(), alpha());
1175  else
1176  ct.argb.green = green * 0x101;
1177 }
void setRgb(int r, int g, int b, int a=255)
Sets the RGB value to r, g, b and the alpha value to a.
Definition: qcolor.cpp:980
union QColor::@220 ct
int red() const
int green() const
Spec cspec
Definition: qcolor.h:239
int alpha() const
int blue() const
#define QCOLOR_INT_RANGE_CHECK(fn, var)
Definition: qcolor.cpp:281

◆ setGreenF()

void QColor::setGreenF ( qreal  green)

Sets the green color component of this color to green.

Float components are specified in the range 0.0-1.0.

See also
greenF(), green(), setRgbF()

Definition at line 1255 of file qcolor.cpp.

Referenced by qt_premultiplyColor().

1256 {
1257  QCOLOR_REAL_RANGE_CHECK("QColor::setGreenF", green);
1258  if (cspec != Rgb)
1259  setRgbF(redF(), green, blueF(), alphaF());
1260  else
1261  ct.argb.green = qRound(green * USHRT_MAX);
1262 }
qreal alphaF() const
Returns the alpha color component of this color.
Definition: qcolor.cpp:1106
union QColor::@220 ct
int green() const
void setRgbF(qreal r, qreal g, qreal b, qreal a=1.0)
Sets the color channels of this color to r (red), g (green), b (blue) and a (alpha, transparency).
Definition: qcolor.cpp:954
Spec cspec
Definition: qcolor.h:239
qreal redF() const
Returns the red color component of this color.
Definition: qcolor.cpp:1213
qreal blueF() const
Returns the blue color component of this color.
Definition: qcolor.cpp:1269
#define QCOLOR_REAL_RANGE_CHECK(fn, var)
Definition: qcolor.cpp:289
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ setHsl()

void QColor::setHsl ( int  h,
int  s,
int  l,
int  a = 255 
)

Sets a HSL color value; h is the hue, s is the saturation, l is the lightness and a is the alpha component of the HSL color.

Since
4.6

The saturation, value and alpha-channel values must be in the range 0-255, and the hue value must be greater than -1.

See also
getHsl(), setHslF()

Definition at line 861 of file qcolor.cpp.

Referenced by QColor().

862 {
863  if (h < -1 || (uint)s > 255 || (uint)l > 255 || (uint)a > 255) {
864  qWarning("QColor::setHsv: HSV parameters out of range");
865  invalidate();
866  return;
867  }
868 
869  cspec = Hsl;
870  ct.ahsl.alpha = a * 0x101;
871  ct.ahsl.hue = h == -1 ? USHRT_MAX : (h % 360) * 100;
872  ct.ahsl.saturation = s * 0x101;
873  ct.ahsl.lightness = l * 0x101;
874  ct.ahsl.pad = 0;
875 }
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a
void invalidate()
Marks the color as invalid and sets all components to zero (alpha is set to fully opaque for compatib...
Definition: qcolor.cpp:2563
Q_CORE_EXPORT void qWarning(const char *,...)
unsigned int uint
Definition: qglobal.h:996
QFactoryLoader * l

◆ setHslF()

void QColor::setHslF ( qreal  h,
qreal  s,
qreal  l,
qreal  a = 1.0 
)

Sets a HSL color lightness; h is the hue, s is the saturation, l is the lightness and a is the alpha component of the HSL color.

Since
4.6

All the values must be in the range 0.0-1.0.

See also
getHslF(), setHsl()

Definition at line 829 of file qcolor.cpp.

830 {
831  if (((h < qreal(0.0) || h > qreal(1.0)) && h != qreal(-1.0))
832  || (s < qreal(0.0) || s > qreal(1.0))
833  || (l < qreal(0.0) || l > qreal(1.0))
834  || (a < qreal(0.0) || a > qreal(1.0))) {
835  qWarning("QColor::setHsvF: HSV parameters out of range");
836  return;
837  }
838 
839  cspec = Hsl;
840  ct.ahsl.alpha = qRound(a * USHRT_MAX);
841  ct.ahsl.hue = h == qreal(-1.0) ? USHRT_MAX : qRound(h * 36000);
842  ct.ahsl.saturation = qRound(s * USHRT_MAX);
843  ct.ahsl.lightness = qRound(l * USHRT_MAX);
844  ct.ahsl.pad = 0;
845 }
double qreal
Definition: qglobal.h:1193
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a
Q_CORE_EXPORT void qWarning(const char *,...)
QFactoryLoader * l
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ setHsv()

void QColor::setHsv ( int  h,
int  s,
int  v,
int  a = 255 
)

Sets a HSV color value; h is the hue, s is the saturation, v is the value and a is the alpha component of the HSV color.

The saturation, value and alpha-channel values must be in the range 0-255, and the hue value must be greater than -1.

See also
getHsv(), setHsvF(), {QColor::The HSV Color Model}{The HSV Color Model}

Definition at line 734 of file qcolor.cpp.

Referenced by darkenPixmap(), QCleanlooksStyle::drawComplexControl(), QGtkStyle::drawComplexControl(), QCleanlooksStyle::drawControl(), QStyleHelper::drawDial(), QCleanlooksStyle::drawPrimitive(), QColorShower::hsvEd(), QColorLuminancePicker::paintEvent(), QColor(), qt_cleanlooks_draw_mdibutton(), QColorPicker::resizeEvent(), QColorShower::setHsv(), and QGtkStyle::standardPalette().

735 {
736  if (h < -1 || (uint)s > 255 || (uint)v > 255 || (uint)a > 255) {
737  qWarning("QColor::setHsv: HSV parameters out of range");
738  invalidate();
739  return;
740  }
741 
742  cspec = Hsv;
743  ct.ahsv.alpha = a * 0x101;
744  ct.ahsv.hue = h == -1 ? USHRT_MAX : (h % 360) * 100;
745  ct.ahsv.saturation = s * 0x101;
746  ct.ahsv.value = v * 0x101;
747  ct.ahsv.pad = 0;
748 }
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a
void invalidate()
Marks the color as invalid and sets all components to zero (alpha is set to fully opaque for compatib...
Definition: qcolor.cpp:2563
Q_CORE_EXPORT void qWarning(const char *,...)
unsigned int uint
Definition: qglobal.h:996

◆ setHsvF()

void QColor::setHsvF ( qreal  h,
qreal  s,
qreal  v,
qreal  a = 1.0 
)

Sets a HSV color value; h is the hue, s is the saturation, v is the value and a is the alpha component of the HSV color.

All the values must be in the range 0.0-1.0.

See also
getHsvF(), setHsv(), {QColor::The HSV Color Model}{The HSV Color Model}

Definition at line 706 of file qcolor.cpp.

Referenced by QMacStyle::drawControl().

707 {
708  if (((h < qreal(0.0) || h > qreal(1.0)) && h != qreal(-1.0))
709  || (s < qreal(0.0) || s > qreal(1.0))
710  || (v < qreal(0.0) || v > qreal(1.0))
711  || (a < qreal(0.0) || a > qreal(1.0))) {
712  qWarning("QColor::setHsvF: HSV parameters out of range");
713  return;
714  }
715 
716  cspec = Hsv;
717  ct.ahsv.alpha = qRound(a * USHRT_MAX);
718  ct.ahsv.hue = h == qreal(-1.0) ? USHRT_MAX : qRound(h * 36000);
719  ct.ahsv.saturation = qRound(s * USHRT_MAX);
720  ct.ahsv.value = qRound(v * USHRT_MAX);
721  ct.ahsv.pad = 0;
722 }
double qreal
Definition: qglobal.h:1193
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a
Q_CORE_EXPORT void qWarning(const char *,...)
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ setNamedColor()

void QColor::setNamedColor ( const QString name)

Sets the RGB value of this QColor to name, which may be in one of these formats:

  • #RGB (each of R, G, and B is a single hex digit)
  • #RRGGBB
  • #RRRGGGBBB
  • #RRRRGGGGBBBB
  • A name from the list of colors defined in the list of SVG color keyword names provided by the World Wide Web Consortium; for example, "steelblue" or "gainsboro". These color names work on all platforms. Note that these color names are not the same as defined by the Qt::GlobalColor enums, e.g. "green" and Qt::green does not refer to the same color.
  • transparent - representing the absence of a color.
  • X11 only: If allowX11ColorNames() returns true, any valid X11 color name. See the documentation for XParseColor() for information about valid X11 color names.

The color is invalid if name cannot be parsed.

See also
QColor(), name(), isValid(), allowX11ColorNames()

Definition at line 560 of file qcolor.cpp.

Referenced by QTextHtmlParser::applyAttributes(), and QCss::Parser::parseHexColor().

561 {
562  setColorFromString(name);
563 }
bool setColorFromString(const QString &name)
Definition: qcolor.cpp:584

◆ setRed()

void QColor::setRed ( int  red)

Sets the red color component of this color to red.

Integer components are specified in the range 0-255.

See also
red(), redF(), setRgb()

Definition at line 1143 of file qcolor.cpp.

Referenced by QCommandLinkButtonPrivate::mergedColors(), and mergedColors().

1144 {
1145  QCOLOR_INT_RANGE_CHECK("QColor::setRed", red);
1146  if (cspec != Rgb)
1147  setRgb(red, green(), blue(), alpha());
1148  else
1149  ct.argb.red = red * 0x101;
1150 }
void setRgb(int r, int g, int b, int a=255)
Sets the RGB value to r, g, b and the alpha value to a.
Definition: qcolor.cpp:980
union QColor::@220 ct
int red() const
int green() const
Spec cspec
Definition: qcolor.h:239
int alpha() const
int blue() const
#define QCOLOR_INT_RANGE_CHECK(fn, var)
Definition: qcolor.cpp:281

◆ setRedF()

void QColor::setRedF ( qreal  red)

Sets the red color component of this color to red.

Float components are specified in the range 0.0-1.0.

See also
redF(), red(), setRgbF()

Definition at line 1227 of file qcolor.cpp.

Referenced by qt_premultiplyColor().

1228 {
1229  QCOLOR_REAL_RANGE_CHECK("QColor::setRedF", red);
1230  if (cspec != Rgb)
1231  setRgbF(red, greenF(), blueF(), alphaF());
1232  else
1233  ct.argb.red = qRound(red * USHRT_MAX);
1234 }
qreal alphaF() const
Returns the alpha color component of this color.
Definition: qcolor.cpp:1106
union QColor::@220 ct
int red() const
qreal greenF() const
Returns the green color component of this color.
Definition: qcolor.cpp:1241
void setRgbF(qreal r, qreal g, qreal b, qreal a=1.0)
Sets the color channels of this color to r (red), g (green), b (blue) and a (alpha, transparency).
Definition: qcolor.cpp:954
Spec cspec
Definition: qcolor.h:239
qreal blueF() const
Returns the blue color component of this color.
Definition: qcolor.cpp:1269
#define QCOLOR_REAL_RANGE_CHECK(fn, var)
Definition: qcolor.cpp:289
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ setRgb() [1/2]

void QColor::setRgb ( int  r,
int  g,
int  b,
int  a = 255 
)

Sets the RGB value to r, g, b and the alpha value to a.

All the values must be in the range 0-255.

See also
rgb(), getRgb(), setRgbF()

Definition at line 980 of file qcolor.cpp.

Referenced by QmlJSDebugger::ColorPickerTool::ColorPickerTool(), operator>>(), qBrushDark(), qBrushLight(), qBrushSetAlphaF(), QColor(), resolveColor(), rgb2hsv(), setBlue(), setColorFromString(), setGreen(), and setRed().

981 {
982  if ((uint)r > 255 || (uint)g > 255 || (uint)b > 255 || (uint)a > 255) {
983  qWarning("QColor::setRgb: RGB parameters out of range");
984  invalidate();
985  return;
986  }
987 
988  cspec = Rgb;
989  ct.argb.alpha = a * 0x101;
990  ct.argb.red = r * 0x101;
991  ct.argb.green = g * 0x101;
992  ct.argb.blue = b * 0x101;
993  ct.argb.pad = 0;
994 }
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a
void invalidate()
Marks the color as invalid and sets all components to zero (alpha is set to fully opaque for compatib...
Definition: qcolor.cpp:2563
Q_CORE_EXPORT void qWarning(const char *,...)
unsigned int uint
Definition: qglobal.h:996

◆ setRgb() [2/2]

void QColor::setRgb ( QRgb  rgb)

Sets the RGB value to rgb.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

The alpha value is set to opaque.

Definition at line 1066 of file qcolor.cpp.

1067 {
1068  cspec = Rgb;
1069  ct.argb.alpha = 0xffff;
1070  ct.argb.red = qRed(rgb) * 0x101;
1071  ct.argb.green = qGreen(rgb) * 0x101;
1072  ct.argb.blue = qBlue(rgb) * 0x101;
1073  ct.argb.pad = 0;
1074 }
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
int qRed(QRgb rgb)
Returns the red component of the ARGB quadruplet rgb.
Definition: qrgb.h:57
int qGreen(QRgb rgb)
Returns the green component of the ARGB quadruplet rgb.
Definition: qrgb.h:60
int qBlue(QRgb rgb)
Returns the blue component of the ARGB quadruplet rgb.
Definition: qrgb.h:63
QRgb rgb() const
Returns the RGB value of the color.
Definition: qcolor.cpp:1051

◆ setRgba()

void QColor::setRgba ( QRgb  rgba)

Use setRgb() instead.

Sets the RGB value to rgba, including its alpha.

See also
rgba(), rgb()

Definition at line 1031 of file qcolor.cpp.

Referenced by setColorFromString(), and QColorShower::updateQColor().

1032 {
1033  cspec = Rgb;
1034  ct.argb.alpha = qAlpha(rgba) * 0x101;
1035  ct.argb.red = qRed(rgba) * 0x101;
1036  ct.argb.green = qGreen(rgba) * 0x101;
1037  ct.argb.blue = qBlue(rgba) * 0x101;
1038  ct.argb.pad = 0;
1039 }
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
int qRed(QRgb rgb)
Returns the red component of the ARGB quadruplet rgb.
Definition: qrgb.h:57
int qAlpha(QRgb rgba)
Returns the alpha component of the ARGB quadruplet rgba.
Definition: qrgb.h:66
QRgb rgba() const
Returns the RGB value of the color, including its alpha.
Definition: qcolor.cpp:1019
int qGreen(QRgb rgb)
Returns the green component of the ARGB quadruplet rgb.
Definition: qrgb.h:60
int qBlue(QRgb rgb)
Returns the blue component of the ARGB quadruplet rgb.
Definition: qrgb.h:63

◆ setRgbF()

void QColor::setRgbF ( qreal  r,
qreal  g,
qreal  b,
qreal  a = 1.0 
)

Sets the color channels of this color to r (red), g (green), b (blue) and a (alpha, transparency).

All values must be in the range 0.0-1.0.

See also
rgb(), getRgbF(), setRgb()

Definition at line 954 of file qcolor.cpp.

Referenced by qcolorFromCGColor(), QInternalMimeData::retrieveData(), setBlueF(), setGreenF(), setRedF(), and QDeclarativeEnginePrivate::tint().

955 {
956  if (r < qreal(0.0) || r > qreal(1.0)
957  || g < qreal(0.0) || g > qreal(1.0)
958  || b < qreal(0.0) || b > qreal(1.0)
959  || a < qreal(0.0) || a > qreal(1.0)) {
960  qWarning("QColor::setRgbF: RGB parameters out of range");
961  invalidate();
962  return;
963  }
964 
965  cspec = Rgb;
966  ct.argb.alpha = qRound(a * USHRT_MAX);
967  ct.argb.red = qRound(r * USHRT_MAX);
968  ct.argb.green = qRound(g * USHRT_MAX);
969  ct.argb.blue = qRound(b * USHRT_MAX);
970  ct.argb.pad = 0;
971 }
double qreal
Definition: qglobal.h:1193
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a
void invalidate()
Marks the color as invalid and sets all components to zero (alpha is set to fully opaque for compatib...
Definition: qcolor.cpp:2563
Q_CORE_EXPORT void qWarning(const char *,...)
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ spec()

Spec QColor::spec ( ) const
inline

Returns how the color was specified.

See also
Spec, convertTo()

Definition at line 88 of file qcolor.h.

Referenced by operator<<(), and QColorDialogPrivate::setCocoaPanelColor().

89  { return cspec; }
Spec cspec
Definition: qcolor.h:239

◆ toCmyk()

QColor QColor::toCmyk ( ) const

Creates and returns a CMYK QColor based on this color.

See also
fromCmyk(), convertTo(), isValid(), {QColor::The CMYK Color Model}{The CMYK Color Model}

Definition at line 1891 of file qcolor.cpp.

Referenced by blackF(), convertTo(), cyanF(), getCmyk(), getCmykF(), lightnessF(), magentaF(), toCmyk(), and yellowF().

1892 {
1893  if (!isValid() || cspec == Cmyk)
1894  return *this;
1895  if (cspec != Rgb)
1896  return toRgb().toCmyk();
1897 
1898  QColor color;
1899  color.cspec = Cmyk;
1900  color.ct.acmyk.alpha = ct.argb.alpha;
1901 
1902  // rgb -> cmy
1903  const qreal r = ct.argb.red / qreal(USHRT_MAX);
1904  const qreal g = ct.argb.green / qreal(USHRT_MAX);
1905  const qreal b = ct.argb.blue / qreal(USHRT_MAX);
1906  qreal c = qreal(1.0) - r;
1907  qreal m = qreal(1.0) - g;
1908  qreal y = qreal(1.0) - b;
1909 
1910  // cmy -> cmyk
1911  const qreal k = qMin(c, qMin(m, y));
1912 
1913  if (!qFuzzyIsNull(k - 1)) {
1914  c = (c - k) / (qreal(1.0) - k);
1915  m = (m - k) / (qreal(1.0) - k);
1916  y = (y - k) / (qreal(1.0) - k);
1917  }
1918 
1919  color.ct.acmyk.cyan = qRound(c * USHRT_MAX);
1920  color.ct.acmyk.magenta = qRound(m * USHRT_MAX);
1921  color.ct.acmyk.yellow = qRound(y * USHRT_MAX);
1922  color.ct.acmyk.black = qRound(k * USHRT_MAX);
1923 
1924  return color;
1925 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
QColor toCmyk() const
Creates and returns a CMYK QColor based on this color.
Definition: qcolor.cpp:1891
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
QColor toRgb() const
Create and returns an RGB QColor based on this color.
Definition: qcolor.cpp:1636
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
bool isValid() const
Returns true if the color is valid; otherwise returns false.
Definition: qcolor.h:295
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
struct QColor::@220::@223 acmyk

◆ toHsl()

QColor QColor::toHsl ( ) const

Creates and returns an HSL QColor based on this color.

See also
fromHsl(), convertTo(), isValid()

Definition at line 1834 of file qcolor.cpp.

Referenced by convertTo(), getHsl(), getHslF(), hslHue(), hslHueF(), hslSaturation(), hslSaturationF(), lightnessF(), and toHsl().

1835 {
1836  if (!isValid() || cspec == Hsl)
1837  return *this;
1838 
1839  if (cspec != Rgb)
1840  return toRgb().toHsl();
1841 
1842  QColor color;
1843  color.cspec = Hsl;
1844  color.ct.ahsl.alpha = ct.argb.alpha;
1845  color.ct.ahsl.pad = 0;
1846 
1847  const qreal r = ct.argb.red / qreal(USHRT_MAX);
1848  const qreal g = ct.argb.green / qreal(USHRT_MAX);
1849  const qreal b = ct.argb.blue / qreal(USHRT_MAX);
1850  const qreal max = Q_MAX_3(r, g, b);
1851  const qreal min = Q_MIN_3(r, g, b);
1852  const qreal delta = max - min;
1853  const qreal delta2 = max + min;
1854  const qreal lightness = qreal(0.5) * delta2;
1855  color.ct.ahsl.lightness = qRound(lightness * USHRT_MAX);
1856  if (qFuzzyIsNull(delta)) {
1857  // achromatic case, hue is undefined
1858  color.ct.ahsl.hue = USHRT_MAX;
1859  color.ct.ahsl.saturation = 0;
1860  } else {
1861  // chromatic case
1862  qreal hue = 0;
1863  if (lightness < qreal(0.5))
1864  color.ct.ahsl.saturation = qRound((delta / delta2) * USHRT_MAX);
1865  else
1866  color.ct.ahsl.saturation = qRound((delta / (qreal(2.0) - delta2)) * USHRT_MAX);
1867  if (qFuzzyCompare(r, max)) {
1868  hue = ((g - b) /delta);
1869  } else if (qFuzzyCompare(g, max)) {
1870  hue = (qreal(2.0) + (b - r) / delta);
1871  } else if (qFuzzyCompare(b, max)) {
1872  hue = (qreal(4.0) + (r - g) / delta);
1873  } else {
1874  Q_ASSERT_X(false, "QColor::toHsv", "internal error");
1875  }
1876  hue *= qreal(60.0);
1877  if (hue < qreal(0.0))
1878  hue += qreal(360.0);
1879  color.ct.ahsl.hue = qRound(hue * 100);
1880  }
1881 
1882  return color;
1883 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
#define Q_MAX_3(a, b, c)
Definition: qcolor.cpp:1773
double qreal
Definition: qglobal.h:1193
int lightness() const
union QColor::@220 ct
struct QColor::@220::@224 ahsl
Spec cspec
Definition: qcolor.h:239
static Q_DECL_CONSTEXPR bool qFuzzyCompare(double p1, double p2)
Definition: qglobal.h:2030
QColor toRgb() const
Create and returns an RGB QColor based on this color.
Definition: qcolor.cpp:1636
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
int hue() const
bool isValid() const
Returns true if the color is valid; otherwise returns false.
Definition: qcolor.h:295
QColor toHsl() const
Creates and returns an HSL QColor based on this color.
Definition: qcolor.cpp:1834
#define Q_MIN_3(a, b, c)
Definition: qcolor.cpp:1774
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ toHsv()

QColor QColor::toHsv ( ) const

Creates and returns an HSV QColor based on this color.

See also
fromHsv(), convertTo(), isValid(), {QColor::The HSV Color Model}{The HSV Color Model}

Definition at line 1783 of file qcolor.cpp.

Referenced by convertTo(), dark(), getHsv(), getHsvF(), hsvHue(), hsvHueF(), hsvSaturation(), hsvSaturationF(), light(), toHsv(), and valueF().

1784 {
1785  if (!isValid() || cspec == Hsv)
1786  return *this;
1787 
1788  if (cspec != Rgb)
1789  return toRgb().toHsv();
1790 
1791  QColor color;
1792  color.cspec = Hsv;
1793  color.ct.ahsv.alpha = ct.argb.alpha;
1794  color.ct.ahsv.pad = 0;
1795 
1796  const qreal r = ct.argb.red / qreal(USHRT_MAX);
1797  const qreal g = ct.argb.green / qreal(USHRT_MAX);
1798  const qreal b = ct.argb.blue / qreal(USHRT_MAX);
1799  const qreal max = Q_MAX_3(r, g, b);
1800  const qreal min = Q_MIN_3(r, g, b);
1801  const qreal delta = max - min;
1802  color.ct.ahsv.value = qRound(max * USHRT_MAX);
1803  if (qFuzzyIsNull(delta)) {
1804  // achromatic case, hue is undefined
1805  color.ct.ahsv.hue = USHRT_MAX;
1806  color.ct.ahsv.saturation = 0;
1807  } else {
1808  // chromatic case
1809  qreal hue = 0;
1810  color.ct.ahsv.saturation = qRound((delta / max) * USHRT_MAX);
1811  if (qFuzzyCompare(r, max)) {
1812  hue = ((g - b) /delta);
1813  } else if (qFuzzyCompare(g, max)) {
1814  hue = (qreal(2.0) + (b - r) / delta);
1815  } else if (qFuzzyCompare(b, max)) {
1816  hue = (qreal(4.0) + (r - g) / delta);
1817  } else {
1818  Q_ASSERT_X(false, "QColor::toHsv", "internal error");
1819  }
1820  hue *= qreal(60.0);
1821  if (hue < qreal(0.0))
1822  hue += qreal(360.0);
1823  color.ct.ahsv.hue = qRound(hue * 100);
1824  }
1825 
1826  return color;
1827 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
#define Q_MAX_3(a, b, c)
Definition: qcolor.cpp:1773
double qreal
Definition: qglobal.h:1193
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
static Q_DECL_CONSTEXPR bool qFuzzyCompare(double p1, double p2)
Definition: qglobal.h:2030
QColor toHsv() const
Creates and returns an HSV QColor based on this color.
Definition: qcolor.cpp:1783
struct QColor::@220::@222 ahsv
QColor toRgb() const
Create and returns an RGB QColor based on this color.
Definition: qcolor.cpp:1636
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
int hue() const
bool isValid() const
Returns true if the color is valid; otherwise returns false.
Definition: qcolor.h:295
#define Q_MIN_3(a, b, c)
Definition: qcolor.cpp:1774
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ toRgb()

QColor QColor::toRgb ( ) const

Create and returns an RGB QColor based on this color.

See also
fromRgb(), convertTo(), isValid()

Definition at line 1636 of file qcolor.cpp.

Referenced by blueF(), convertTo(), getRgb(), getRgbF(), greenF(), redF(), rgb(), rgba(), setAlphaF(), setGreen(), setRed(), toCmyk(), toHsl(), and toHsv().

1637 {
1638  if (!isValid() || cspec == Rgb)
1639  return *this;
1640 
1641  QColor color;
1642  color.cspec = Rgb;
1643  color.ct.argb.alpha = ct.argb.alpha;
1644  color.ct.argb.pad = 0;
1645 
1646  switch (cspec) {
1647  case Hsv:
1648  {
1649  if (ct.ahsv.saturation == 0 || ct.ahsv.hue == USHRT_MAX) {
1650  // achromatic case
1651  color.ct.argb.red = color.ct.argb.green = color.ct.argb.blue = ct.ahsv.value;
1652  break;
1653  }
1654 
1655  // chromatic case
1656  const qreal h = ct.ahsv.hue == 36000 ? 0 : ct.ahsv.hue / qreal(6000.);
1657  const qreal s = ct.ahsv.saturation / qreal(USHRT_MAX);
1658  const qreal v = ct.ahsv.value / qreal(USHRT_MAX);
1659  const int i = int(h);
1660  const qreal f = h - i;
1661  const qreal p = v * (qreal(1.0) - s);
1662 
1663  if (i & 1) {
1664  const qreal q = v * (qreal(1.0) - (s * f));
1665 
1666  switch (i) {
1667  case 1:
1668  color.ct.argb.red = qRound(q * USHRT_MAX);
1669  color.ct.argb.green = qRound(v * USHRT_MAX);
1670  color.ct.argb.blue = qRound(p * USHRT_MAX);
1671  break;
1672  case 3:
1673  color.ct.argb.red = qRound(p * USHRT_MAX);
1674  color.ct.argb.green = qRound(q * USHRT_MAX);
1675  color.ct.argb.blue = qRound(v * USHRT_MAX);
1676  break;
1677  case 5:
1678  color.ct.argb.red = qRound(v * USHRT_MAX);
1679  color.ct.argb.green = qRound(p * USHRT_MAX);
1680  color.ct.argb.blue = qRound(q * USHRT_MAX);
1681  break;
1682  }
1683  } else {
1684  const qreal t = v * (qreal(1.0) - (s * (qreal(1.0) - f)));
1685 
1686  switch (i) {
1687  case 0:
1688  color.ct.argb.red = qRound(v * USHRT_MAX);
1689  color.ct.argb.green = qRound(t * USHRT_MAX);
1690  color.ct.argb.blue = qRound(p * USHRT_MAX);
1691  break;
1692  case 2:
1693  color.ct.argb.red = qRound(p * USHRT_MAX);
1694  color.ct.argb.green = qRound(v * USHRT_MAX);
1695  color.ct.argb.blue = qRound(t * USHRT_MAX);
1696  break;
1697  case 4:
1698  color.ct.argb.red = qRound(t * USHRT_MAX);
1699  color.ct.argb.green = qRound(p * USHRT_MAX);
1700  color.ct.argb.blue = qRound(v * USHRT_MAX);
1701  break;
1702  }
1703  }
1704  break;
1705  }
1706  case Hsl:
1707  {
1708  if (ct.ahsl.saturation == 0 || ct.ahsl.hue == USHRT_MAX) {
1709  // achromatic case
1710  color.ct.argb.red = color.ct.argb.green = color.ct.argb.blue = ct.ahsl.lightness;
1711  } else if (ct.ahsl.lightness == 0) {
1712  // lightness 0
1713  color.ct.argb.red = color.ct.argb.green = color.ct.argb.blue = 0;
1714  } else {
1715  // chromatic case
1716  const qreal h = ct.ahsl.hue == 36000 ? 0 : ct.ahsl.hue / qreal(36000.);
1717  const qreal s = ct.ahsl.saturation / qreal(USHRT_MAX);
1718  const qreal l = ct.ahsl.lightness / qreal(USHRT_MAX);
1719 
1720  qreal temp2;
1721  if (l < qreal(0.5))
1722  temp2 = l * (qreal(1.0) + s);
1723  else
1724  temp2 = l + s - (l * s);
1725 
1726  const qreal temp1 = (qreal(2.0) * l) - temp2;
1727  qreal temp3[3] = { h + (qreal(1.0) / qreal(3.0)),
1728  h,
1729  h - (qreal(1.0) / qreal(3.0)) };
1730 
1731  for (int i = 0; i != 3; ++i) {
1732  if (temp3[i] < qreal(0.0))
1733  temp3[i] += qreal(1.0);
1734  else if (temp3[i] > qreal(1.0))
1735  temp3[i] -= qreal(1.0);
1736 
1737  const qreal sixtemp3 = temp3[i] * qreal(6.0);
1738  if (sixtemp3 < qreal(1.0))
1739  color.ct.array[i+1] = qRound((temp1 + (temp2 - temp1) * sixtemp3) * USHRT_MAX);
1740  else if ((temp3[i] * qreal(2.0)) < qreal(1.0))
1741  color.ct.array[i+1] = qRound(temp2 * USHRT_MAX);
1742  else if ((temp3[i] * qreal(3.0)) < qreal(2.0))
1743  color.ct.array[i+1] = qRound((temp1 + (temp2 -temp1) * (qreal(2.0) /qreal(3.0) - temp3[i]) * qreal(6.0)) * USHRT_MAX);
1744  else
1745  color.ct.array[i+1] = qRound(temp1 * USHRT_MAX);
1746  }
1747  color.ct.argb.red = color.ct.argb.red == 1 ? 0 : color.ct.argb.red;
1748  color.ct.argb.green = color.ct.argb.green == 1 ? 0 : color.ct.argb.green;
1749  color.ct.argb.blue = color.ct.argb.blue == 1 ? 0 : color.ct.argb.blue;
1750  }
1751  break;
1752  }
1753  case Cmyk:
1754  {
1755  const qreal c = ct.acmyk.cyan / qreal(USHRT_MAX);
1756  const qreal m = ct.acmyk.magenta / qreal(USHRT_MAX);
1757  const qreal y = ct.acmyk.yellow / qreal(USHRT_MAX);
1758  const qreal k = ct.acmyk.black / qreal(USHRT_MAX);
1759 
1760  color.ct.argb.red = qRound((qreal(1.0) - (c * (qreal(1.0) - k) + k)) * USHRT_MAX);
1761  color.ct.argb.green = qRound((qreal(1.0) - (m * (qreal(1.0) - k) + k)) * USHRT_MAX);
1762  color.ct.argb.blue = qRound((qreal(1.0) - (y * (qreal(1.0) - k) + k)) * USHRT_MAX);
1763  break;
1764  }
1765  default:
1766  break;
1767  }
1768 
1769  return color;
1770 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
struct QColor::@220::@221 argb
ushort array[5]
Definition: qcolor.h:269
QFactoryLoader * l
bool isValid() const
Returns true if the color is valid; otherwise returns false.
Definition: qcolor.h:295
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ value()

int QColor::value ( ) const

Referenced by hsvSaturation().

◆ valueF()

qreal QColor::valueF ( ) const

Returns the value color component of this color.

See also
value() getHsvF(), {QColor::The HSV Color Model}{The HSV Color Model}

Definition at line 1416 of file qcolor.cpp.

Referenced by operator<<(), and valueF().

1417 {
1418  if (cspec != Invalid && cspec != Hsv)
1419  return toHsv().valueF();
1420  return ct.ahsv.value / qreal(USHRT_MAX);
1421 }
double qreal
Definition: qglobal.h:1193
union QColor::@220 ct
qreal valueF() const
Returns the value color component of this color.
Definition: qcolor.cpp:1416
Spec cspec
Definition: qcolor.h:239
QColor toHsv() const
Creates and returns an HSV QColor based on this color.
Definition: qcolor.cpp:1783

◆ yellow()

int QColor::yellow ( ) const

Referenced by lightnessF().

◆ yellowF()

qreal QColor::yellowF ( ) const

Returns the yellow color component of this color.

See also
yellow(), getCmykF(), {QColor::The CMYK Color Model}{The CMYK Color Model}

Definition at line 1611 of file qcolor.cpp.

Referenced by operator<<(), and yellowF().

1612 {
1613  if (cspec != Invalid && cspec != Cmyk)
1614  return toCmyk().yellowF();
1615  return ct.acmyk.yellow / qreal(USHRT_MAX);
1616 }
double qreal
Definition: qglobal.h:1193
QColor toCmyk() const
Creates and returns a CMYK QColor based on this color.
Definition: qcolor.cpp:1891
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
qreal yellowF() const
Returns the yellow color component of this color.
Definition: qcolor.cpp:1611

Friends and Related Functions

◆ operator<<

QDataStream & operator<< ( QDataStream stream,
const QColor color 
)
friend

Writes the color to the stream.

See also
{Serializing Qt Data Types}

Definition at line 2638 of file qcolor.cpp.

2639 {
2640  if (stream.version() < 7) {
2641  if (!color.isValid())
2642  return stream << quint32(0x49000000);
2643  quint32 p = (quint32)color.rgb();
2644  if (stream.version() == 1) // Swap red and blue
2645  p = ((p << 16) & 0xff0000) | ((p >> 16) & 0xff) | (p & 0xff00ff00);
2646  return stream << p;
2647  }
2648 
2649  qint8 s = color.cspec;
2650  quint16 a = color.ct.argb.alpha;
2651  quint16 r = color.ct.argb.red;
2652  quint16 g = color.ct.argb.green;
2653  quint16 b = color.ct.argb.blue;
2654  quint16 p = color.ct.argb.pad;
2655 
2656  stream << s;
2657  stream << a;
2658  stream << r;
2659  stream << g;
2660  stream << b;
2661  stream << p;
2662 
2663  return stream;
2664 }
union QColor::@220 ct
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a
struct QColor::@220::@221 argb
signed char qint8
Definition: qglobal.h:933
static FILE * stream
unsigned short quint16
Definition: qglobal.h:936
int version() const
Returns the version number of the data serialization format.
Definition: qdatastream.h:212
unsigned int quint32
Definition: qglobal.h:938
bool isValid() const
Returns true if the color is valid; otherwise returns false.
Definition: qcolor.h:295
QRgb rgb() const
Returns the RGB value of the color.
Definition: qcolor.cpp:1051

◆ operator>>

QDataStream & operator>> ( QDataStream stream,
QColor color 
)
friend

Reads the color from the stream.

See also
{Serializing Qt Data Types}

Definition at line 2677 of file qcolor.cpp.

2678 {
2679  if (stream.version() < 7) {
2680  quint32 p;
2681  stream >> p;
2682  if (p == 0x49000000) {
2683  color.invalidate();
2684  return stream;
2685  }
2686  if (stream.version() == 1) // Swap red and blue
2687  p = ((p << 16) & 0xff0000) | ((p >> 16) & 0xff) | (p & 0xff00ff00);
2688  color.setRgb(p);
2689  return stream;
2690  }
2691 
2692  qint8 s;
2693  quint16 a, r, g, b, p;
2694  stream >> s;
2695  stream >> a;
2696  stream >> r;
2697  stream >> g;
2698  stream >> b;
2699  stream >> p;
2700 
2701  color.cspec = QColor::Spec(s);
2702  color.ct.argb.alpha = a;
2703  color.ct.argb.red = r;
2704  color.ct.argb.green = g;
2705  color.ct.argb.blue = b;
2706  color.ct.argb.pad = p;
2707 
2708  return stream;
2709 }
void setRgb(int r, int g, int b, int a=255)
Sets the RGB value to r, g, b and the alpha value to a.
Definition: qcolor.cpp:980
union QColor::@220 ct
Spec
The type of color specified, either RGB, HSV, CMYK or HSL.
Definition: qcolor.h:70
Spec cspec
Definition: qcolor.h:239
long ASN1_INTEGER_get ASN1_INTEGER * a
struct QColor::@220::@221 argb
void invalidate()
Marks the color as invalid and sets all components to zero (alpha is set to fully opaque for compatib...
Definition: qcolor.cpp:2563
signed char qint8
Definition: qglobal.h:933
static FILE * stream
unsigned short quint16
Definition: qglobal.h:936
int version() const
Returns the version number of the data serialization format.
Definition: qdatastream.h:212
unsigned int quint32
Definition: qglobal.h:938

◆ qAlpha()

int qAlpha ( QRgb  rgba)
related

Returns the alpha component of the ARGB quadruplet rgba.

See also
qRgb(), QColor::alpha()

Definition at line 66 of file qrgb.h.

Referenced by destStoreARGB32(), fromRgba(), QColor(), setRgba(), and sourceOver().

67 { return rgb >> 24; }
QRgb rgb() const
Returns the RGB value of the color.
Definition: qcolor.cpp:1051

◆ qBlue()

int qBlue ( QRgb  rgb)
related

Returns the blue component of the ARGB quadruplet rgb.

See also
qRgb(), QColor::blue()

Definition at line 63 of file qrgb.h.

Referenced by destStoreARGB32(), findNearestColor(), fromRgb(), fromRgba(), QColor(), qGray(), qIsGray(), qt_convRgbTo16(), qt_write_dib(), setRgb(), setRgba(), and write_pbm_image().

64 { return (rgb & 0xff); }
QRgb rgb() const
Returns the RGB value of the color.
Definition: qcolor.cpp:1051

◆ QColormap

friend class QColormap
friend

Definition at line 272 of file qcolor.h.

◆ qGray() [1/2]

int qGray ( int  r,
int  g,
int  b 
)
related

Returns a gray value (0 to 255) from the (r, g, b) triplet.

The gray value is calculated using the formula (r * 11 + g * 16 + b * 5)/32.

Definition at line 75 of file qrgb.h.

Referenced by destStoreMono(), destStoreMonoLsb(), qGray(), read_dib_body(), write_pbm_image(), and write_xbm_image().

76 { return (r*11+g*16+b*5)/32; }

◆ qGray() [2/2]

int qGray ( QRgb  rgb)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns a gray value (0 to 255) from the given ARGB quadruplet rgb.

The gray value is calculated using the formula (R * 11 + G * 16 + B * 5)/32; the alpha-channel is ignored.

Definition at line 78 of file qrgb.h.

79 { return qGray(qRed(rgb), qGreen(rgb), qBlue(rgb)); }
int qRed(QRgb rgb)
Returns the red component of the ARGB quadruplet rgb.
Definition: qrgb.h:57
int qGray(int r, int g, int b)
Definition: qrgb.h:75
int qGreen(QRgb rgb)
Returns the green component of the ARGB quadruplet rgb.
Definition: qrgb.h:60
int qBlue(QRgb rgb)
Returns the blue component of the ARGB quadruplet rgb.
Definition: qrgb.h:63
QRgb rgb() const
Returns the RGB value of the color.
Definition: qcolor.cpp:1051

◆ qGreen()

int qGreen ( QRgb  rgb)
related

Returns the green component of the ARGB quadruplet rgb.

See also
qRgb(), QColor::green()

Definition at line 60 of file qrgb.h.

Referenced by destStoreARGB32(), findNearestColor(), fromRgb(), fromRgba(), QColor(), qGray(), qIsGray(), qt_convRgbTo16(), qt_write_dib(), setRgb(), setRgba(), and write_pbm_image().

61 { return ((rgb >> 8) & 0xff); }
QRgb rgb() const
Returns the RGB value of the color.
Definition: qcolor.cpp:1051

◆ qRed()

int qRed ( QRgb  rgb)
related

Returns the red component of the ARGB quadruplet rgb.

See also
qRgb(), QColor::red()

Definition at line 57 of file qrgb.h.

Referenced by destStoreARGB32(), findNearestColor(), fromRgb(), fromRgba(), QColor(), qGray(), qIsGray(), qt_convRgbTo16(), qt_write_dib(), setRgb(), setRgba(), and write_pbm_image().

58 { return ((rgb >> 16) & 0xff); }
QRgb rgb() const
Returns the RGB value of the color.
Definition: qcolor.cpp:1051

◆ qRgb()

QRgb qRgb ( int  r,
int  g,
int  b 
)
related

Returns the ARGB quadruplet (255, {r}, {g}, {b}).

See also
qRgba(), qRed(), qGreen(), qBlue()

Definition at line 69 of file qrgb.h.

Referenced by convert_rgb888_to_rgb32_C(), qsvg_get_hex_rgb(), qt_conv16ToRgb(), qt_get_hex_rgb(), read_dib_body(), read_pbm_body(), read_xbm_body(), and rgb().

70 { return (0xffu << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); }

◆ QRgb()

QRgb
related

An ARGB quadruplet on the format #AARRGGBB, equivalent to an unsigned int.

The type also holds a value for the alpha-channel. The default alpha channel is ff, i.e opaque. For more information, see the Alpha-Blended Drawing section.

See also
QColor::rgb(), QColor::rgba()

◆ qRgba()

QRgb qRgba ( int  r,
int  g,
int  b,
int  a 
)
related

Returns the ARGB quadruplet ({a}, {r}, {g}, {b}).

See also
qRgb(), qRed(), qGreen(), qBlue()

Definition at line 72 of file qrgb.h.

Referenced by rgba().

73 { return ((a & 0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); }
long ASN1_INTEGER_get ASN1_INTEGER * a

Properties

◆ acmyk

struct { ... } QColor::acmyk

Referenced by fromCmyk(), fromCmykF(), and toCmyk().

◆ ahsl

struct { ... } QColor::ahsl

Referenced by fromHsl(), fromHslF(), operator==(), and toHsl().

◆ ahsv

struct { ... } QColor::ahsv

◆ alpha

int QColor::alpha

◆ argb

struct { ... } QColor::argb

◆ array

ushort QColor::array[5]

Definition at line 269 of file qcolor.h.

Referenced by toRgb().

◆ black

int QColor::black

Returns the black color component of this color.

See also
blackF(), getCmyk(), {QColor::The CMYK Color Model}{The CMYK Color Model}

Definition at line 260 of file qcolor.h.

Referenced by lightnessF().

◆ blue

int QColor::blue

◆ cspec

Spec QColor::cspec
private

◆ ct

union { ... } QColor::ct

◆ cyan

int QColor::cyan

Returns the cyan color component of this color.

See also
cyanF(), getCmyk(), {QColor::The CMYK Color Model}{The CMYK Color Model}

Definition at line 257 of file qcolor.h.

Referenced by lightnessF().

◆ green

int QColor::green

◆ hue

int QColor::hue

Returns the hue color component of this color.

The color is implicitly converted to HSV.

See also
hsvHue(), hueF(), getHsv(), {QColor::The HSV Color Model}{The HSV Color Model}

Definition at line 250 of file qcolor.h.

Referenced by QCleanlooksStyle::drawComplexControl(), QGtkStyle::drawComplexControl(), QCleanlooksStyle::drawControl(), QStyleHelper::drawDial(), QCleanlooksStyle::drawPrimitive(), hsvHue(), qt_cleanlooks_draw_mdibutton(), and QGtkStyle::standardPalette().

◆ lightness

int QColor::lightness

Returns the lightness color component of this color.

Since
4.6
See also
lightnessF(), getHsl()

Definition at line 266 of file qcolor.h.

Referenced by hslSaturation().

◆ magenta

int QColor::magenta

Returns the magenta color component of this color.

See also
magentaF(), getCmyk(), {QColor::The CMYK Color Model}{The CMYK Color Model}

Definition at line 258 of file qcolor.h.

Referenced by lightnessF().

◆ pad

ushort QColor::pad

Definition at line 246 of file qcolor.h.

◆ red

int QColor::red

◆ saturation

int QColor::saturation

Returns the saturation color component of this color.

The color is implicitly converted to HSV.

See also
hsvSaturation(), saturationF(), getHsv(), {QColor::The HSV Color Model}{The HSV Color Model}

Definition at line 251 of file qcolor.h.

Referenced by QCleanlooksStyle::drawComplexControl(), QGtkStyle::drawComplexControl(), QCleanlooksStyle::drawControl(), QStyleHelper::drawDial(), QCleanlooksStyle::drawPrimitive(), hsvSaturation(), and qt_cleanlooks_draw_mdibutton().

◆ value

int QColor::value

◆ yellow

int QColor::yellow

Returns the yellow color component of this color.

See also
yellowF(), getCmyk(), {QColor::The CMYK Color Model}{The CMYK Color Model}

Definition at line 259 of file qcolor.h.

Referenced by lightnessF().


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