1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
44 #include "qnamespace.h"
45 #include "qdatastream.h"
57 \brief The QColor class provides colors based on RGB, HSV or CMYK values.
63 A color is normally specified in terms of RGB (red, green, and
64 blue) components, but it is also possible to specify it in terms
65 of HSV (hue, saturation, and value) and CMYK (cyan, magenta,
66 yellow and black) components. In addition a color can be specified
67 using a color name. The color name can be any of the SVG 1.0 color
72 \li RGB \li HSV \li CMYK
74 \li \inlineimage qcolor-rgb.png
75 \li \inlineimage qcolor-hsv.png
76 \li \inlineimage qcolor-cmyk.png
79 The QColor constructor creates the color based on RGB values. To
80 create a QColor based on either HSV or CMYK values, use the
81 toHsv() and toCmyk() functions respectively. These functions
82 return a copy of the color using the desired format. In addition
83 the static fromRgb(), fromHsv() and fromCmyk() functions create
84 colors from the specified values. Alternatively, a color can be
85 converted to any of the three formats using the convertTo()
86 function (returning a copy of the color in the desired format), or
87 any of the setRgb(), setHsv() and setCmyk() functions altering \e
88 this color's format. The spec() function tells how the color was
91 A color can be set by passing an RGB string (such as "#112233"),
92 or a color name (such as "blue"), to the setNamedColor() function.
93 The color names are taken from the SVG 1.0 color names. The name()
94 function returns the name of the color in the format
95 "#RRGGBB". Colors can also be set using setRgb(), setHsv() and
96 setCmyk(). To get a lighter or darker color use the lighter() and
97 darker() functions respectively.
99 The isValid() function indicates whether a QColor is legal at
100 all. For example, a RGB color with RGB values out of range is
101 illegal. For performance reasons, QColor mostly disregards illegal
102 colors, and for that reason, the result of using an invalid color
105 The color components can be retrieved individually, e.g with
106 red(), hue() and cyan(). The values of the color components can
107 also be retrieved in one go using the getRgb(), getHsv() and
108 getCmyk() functions. Using the RGB color model, the color
109 components can in addition be accessed with rgb().
111 There are several related non-members: QRgb is a typdef for an
112 unsigned int representing the RGB value triplet (r, g, b). Note
113 that it also can hold a value for the alpha-channel (for more
114 information, see the \l {QColor#Alpha-Blended
115 Drawing}{Alpha-Blended Drawing} section). The qRed(), qBlue() and
116 qGreen() functions return the respective component of the given
117 QRgb value, while the qRgb() and qRgba() functions create and
118 return the QRgb triplet based on the given component
119 values. Finally, the qAlpha() function returns the alpha component
120 of the provided QRgb, and the qGray() function calculates and
121 return a gray value based on the given value.
123 QColor is platform and device independent. The QColormap class
124 maps the color to the hardware.
126 For more information about painting in general, see the \l{Paint
127 System} documentation.
131 \section1 Integer vs. Floating Point Precision
133 QColor supports floating point precision and provides floating
134 point versions of all the color components functions,
135 e.g. getRgbF(), hueF() and fromCmykF(). Note that since the
136 components are stored using 16-bit integers, there might be minor
137 deviations between the values set using, for example, setRgbF()
138 and the values returned by the getRgbF() function due to rounding.
140 While the integer based functions take values in the range 0-255
141 (except hue() which must have values within the range 0-359),
142 the floating point functions accept values in the range 0.0 - 1.0.
144 \section1 Alpha-Blended Drawing
146 QColor also support alpha-blended outlining and filling. The
147 alpha channel of a color specifies the transparency effect, 0
148 represents a fully transparent color, while 255 represents a fully
149 opaque color. For example:
151 \snippet code/src_gui_painting_qcolor.cpp 0
153 The code above produces the following output:
157 The alpha channel of a color can be retrieved and set using the
158 alpha() and setAlpha() functions if its value is an integer, and
159 alphaF() and setAlphaF() if its value is qreal (double). By
160 default, the alpha-channel is set to 255 (opaque). To retrieve and
161 set \e all the RGB color components (including the alpha-channel)
162 in one go, use the rgba() and setRgba() functions.
164 \section1 Predefined Colors
166 There are 20 predefined QColors described by the Qt::GlobalColor enum,
167 including black, white, primary and secondary colors, darker versions
168 of these colors and three shades of gray. QColor also recognizes a
169 variety of color names; the static colorNames() function returns a
170 QStringList color names that QColor knows about.
172 \img qt-colors.png Qt Colors
174 Additionally, the Qt::color0, Qt::color1 and Qt::transparent colors
175 are used for special purposes.
177 Qt::color0 (zero pixel value) and Qt::color1 (non-zero pixel value)
178 are special colors for drawing in QBitmaps. Painting with Qt::color0
179 sets the bitmap bits to 0 (transparent; i.e., background), and painting
180 with Qt::color1 sets the bits to 1 (opaque; i.e., foreground).
182 Qt::transparent is used to indicate a transparent pixel. When painting
183 with this value, a pixel value will be used that is appropriate for the
184 underlying pixel format in use.
186 \section1 The HSV Color Model
188 The RGB model is hardware-oriented. Its representation is close to
189 what most monitors show. In contrast, HSV represents color in a way
190 more suited to the human perception of color. For example, the
191 relationships "stronger than", "darker than", and "the opposite of"
192 are easily expressed in HSV but are much harder to express in RGB.
194 HSV, like RGB, has three components:
197 \li H, for hue, is in the range 0 to 359 if the color is chromatic (not
198 gray), or meaningless if it is gray. It represents degrees on the
199 color wheel familiar to most people. Red is 0 (degrees), green is
200 120, and blue is 240.
202 \inlineimage qcolor-hue.png
204 \li S, for saturation, is in the range 0 to 255, and the bigger it is,
205 the stronger the color is. Grayish colors have saturation near 0; very
206 strong colors have saturation near 255.
208 \inlineimage qcolor-saturation.png
210 \li V, for value, is in the range 0 to 255 and represents lightness or
211 brightness of the color. 0 is black; 255 is as far from black as
214 \inlineimage qcolor-value.png
217 Here are some examples: pure red is H=0, S=255, V=255; a dark red,
218 moving slightly towards the magenta, could be H=350 (equivalent to
219 -10), S=255, V=180; a grayish light red could have H about 0 (say
220 350-359 or 0-10), S about 50-100, and S=255.
222 Qt returns a hue value of -1 for achromatic colors. If you pass a
223 hue value that is too large, Qt forces it into range. Hue 360 or 720 is
224 treated as 0; hue 540 is treated as 180.
226 In addition to the standard HSV model, Qt provides an
227 alpha-channel to feature \l {QColor#Alpha-Blended
228 Drawing}{alpha-blended drawing}.
230 \section1 The HSL Color Model
232 HSL is similar to HSV. Instead of value parameter from HSV,
233 HSL has the lightness parameter.
234 The lightness parameter goes from black to color and from color to white.
235 If you go outside at the night its black or dark gray. At day its colorful but
236 if you look in a really strong light a things they are going to white and
239 \section1 The CMYK Color Model
241 While the RGB and HSV color models are used for display on
242 computer monitors, the CMYK model is used in the four-color
243 printing process of printing presses and some hard-copy
246 CMYK has four components, all in the range 0-255: cyan (C),
247 magenta (M), yellow (Y) and black (K). Cyan, magenta and yellow
248 are called subtractive colors; the CMYK color model creates color
249 by starting with a white surface and then subtracting color by
250 applying the appropriate components. While combining cyan, magenta
251 and yellow gives the color black, subtracting one or more will
252 yield any other color. When combined in various percentages, these
253 three colors can create the entire spectrum of colors.
255 Mixing 100 percent of cyan, magenta and yellow \e does produce
256 black, but the result is unsatisfactory since it wastes ink,
257 increases drying time, and gives a muddy colour when printing. For
258 that reason, black is added in professional printing to provide a
259 solid black tone; hence the term 'four color process'.
261 In addition to the standard CMYK model, Qt provides an
262 alpha-channel to feature \l {QColor#Alpha-Blended
263 Drawing}{alpha-blended drawing}.
265 \sa QPalette, QBrush, QApplication::setColorSpec()
268 #define QCOLOR_INT_RANGE_CHECK(fn, var) \
270 if (var < 0 || var > 255) { \
271 qWarning(#fn": invalid value %d", var); \
272 var = qMax(0, qMin(var, 255)); \
276 #define QCOLOR_REAL_RANGE_CHECK(fn, var) \
278 if (var < qreal(0.0) || var > qreal(1.0)) { \
279 qWarning(#fn": invalid value %g", var); \
280 var = qMax(qreal(0.0), qMin(var, qreal(1.0))); \
284 /*****************************************************************************
285 QColor member functions
286 *****************************************************************************/
291 The type of color specified, either RGB, HSV, CMYK or HSL.
299 \sa spec(), convertTo()
303 \fn Spec QColor::spec() const
305 Returns how the color was specified.
307 \sa Spec, convertTo()
314 Constructs an invalid color with the RGB value (0, 0, 0). An
315 invalid color is a color that is not properly set up for the
316 underlying window system.
318 The alpha value of an invalid color is unspecified.
326 Constructs a new color with a color value of \a color.
328 \sa isValid(), {QColor#Predefined Colors}{Predefined Colors}
330 QColor::QColor(Qt::GlobalColor color)
332 #define QRGB(r, g, b) \
333 QRgb(((0xffu << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff)))
334 #define QRGBA(r, g, b, a) \
335 QRgb(((a & 0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff))
337 static const QRgb global_colors[] = {
338 QRGB(255, 255, 255), // Qt::color0
339 QRGB( 0, 0, 0), // Qt::color1
340 QRGB( 0, 0, 0), // black
341 QRGB(255, 255, 255), // white
343 * From the "The Palette Manager: How and Why" by Ron Gery,
344 * March 23, 1992, archived on MSDN:
346 * The Windows system palette is broken up into two
347 * sections, one with fixed colors and one with colors
348 * that can be changed by applications. The system palette
349 * predefines 20 entries; these colors are known as the
350 * static or reserved colors and consist of the 16 colors
351 * found in the Windows version 3.0 VGA driver and 4
352 * additional colors chosen for their visual appeal. The
353 * DEFAULT_PALETTE stock object is, as the name implies,
354 * the default palette selected into a device context (DC)
355 * and consists of these static colors. Applications can
356 * set the remaining 236 colors using the Palette Manager.
358 * The 20 reserved entries have indices in [0,9] and
359 * [246,255]. We reuse 17 of them.
361 QRGB(128, 128, 128), // index 248 medium gray
362 QRGB(160, 160, 164), // index 247 light gray
363 QRGB(192, 192, 192), // index 7 light gray
364 QRGB(255, 0, 0), // index 249 red
365 QRGB( 0, 255, 0), // index 250 green
366 QRGB( 0, 0, 255), // index 252 blue
367 QRGB( 0, 255, 255), // index 254 cyan
368 QRGB(255, 0, 255), // index 253 magenta
369 QRGB(255, 255, 0), // index 251 yellow
370 QRGB(128, 0, 0), // index 1 dark red
371 QRGB( 0, 128, 0), // index 2 dark green
372 QRGB( 0, 0, 128), // index 4 dark blue
373 QRGB( 0, 128, 128), // index 6 dark cyan
374 QRGB(128, 0, 128), // index 5 dark magenta
375 QRGB(128, 128, 0), // index 3 dark yellow
376 QRGBA(0, 0, 0, 0) // transparent
381 setRgb(qRed(global_colors[color]),
382 qGreen(global_colors[color]),
383 qBlue(global_colors[color]),
384 qAlpha(global_colors[color]));
388 \fn QColor::QColor(int r, int g, int b, int a = 255)
390 Constructs a color with the RGB value \a r, \a g, \a b, and the
391 alpha-channel (transparency) value of \a a.
393 The color is left invalid if any of the arguments are invalid.
395 \sa setRgba(), isValid()
399 Constructs a color with the value \a color. The alpha component is
400 ignored and set to solid.
402 \sa fromRgb(), isValid()
405 QColor::QColor(QRgb color)
408 ct.argb.alpha = 0xffff;
409 ct.argb.red = qRed(color) * 0x101;
410 ct.argb.green = qGreen(color) * 0x101;
411 ct.argb.blue = qBlue(color) * 0x101;
419 Constructs a color with the given \a spec.
421 This function is primarly present to avoid that QColor::Invalid
422 becomes a valid color by accident.
425 QColor::QColor(Spec spec)
447 \fn QColor::QColor(const QString &name)
449 Constructs a named color in the same way as setNamedColor() using
452 The color is left invalid if the \a name cannot be parsed.
454 \sa setNamedColor(), name(), isValid()
458 \fn QColor::QColor(const char *name)
460 Constructs a named color in the same way as setNamedColor() using
463 The color is left invalid if the \a name cannot be parsed.
465 \sa setNamedColor(), name(), isValid()
469 \fn QColor::QColor(const QColor &color)
471 Constructs a color that is a copy of \a color.
477 \fn bool QColor::isValid() const
479 Returns true if the color is valid; otherwise returns false.
483 Returns the name of the color in the format "#RRGGBB"; i.e. a "#"
484 character followed by three two-digit hexadecimal numbers.
489 QString QColor::name() const
492 s.sprintf("#%02x%02x%02x", red(), green(), blue());
497 Sets the RGB value of this QColor to \a name, which may be in one
501 \li #RGB (each of R, G, and B is a single hex digit)
505 \li A name from the list of colors defined in the list of \l{SVG color keyword names}
506 provided by the World Wide Web Consortium; for example, "steelblue" or "gainsboro".
507 These color names work on all platforms. Note that these color names are \e not the
508 same as defined by the Qt::GlobalColor enums, e.g. "green" and Qt::green does not
509 refer to the same color.
510 \li \c transparent - representing the absence of a color.
513 The color is invalid if \a name cannot be parsed.
515 \sa QColor(), name(), isValid()
518 void QColor::setNamedColor(const QString &name)
520 setColorFromString(name);
526 Returns true if the \a name is a valid color name and can
527 be used to construct a valid QColor object, otherwise returns
530 It uses the same algorithm used in setNamedColor().
534 bool QColor::isValidColor(const QString &name)
536 return !name.isEmpty() && QColor().setColorFromString(name);
539 bool QColor::setColorFromString(const QString &name)
541 if (name.isEmpty()) {
546 if (name.startsWith(QLatin1Char('#'))) {
548 if (qt_get_hex_rgb(name.constData(), name.length(), &rgb)) {
557 #ifndef QT_NO_COLORNAMES
559 if (qt_get_named_rgb(name.constData(), name.length(), &rgb)) {
571 Returns a QStringList containing the color names Qt knows about.
573 \sa {QColor#Predefined Colors}{Predefined Colors}
575 QStringList QColor::colorNames()
577 #ifndef QT_NO_COLORNAMES
578 return qt_get_colornames();
580 return QStringList();
585 Sets the contents pointed to by \a h, \a s, \a v, and \a a, to the hue,
586 saturation, value, and alpha-channel (transparency) components of the
589 These components can be retrieved individually using the hueF(),
590 saturationF(), valueF() and alphaF() functions.
592 \sa setHsv(), {QColor#The HSV Color Model}{The HSV Color Model}
594 void QColor::getHsvF(qreal *h, qreal *s, qreal *v, qreal *a) const
599 if (cspec != Invalid && cspec != Hsv) {
600 toHsv().getHsvF(h, s, v, a);
604 *h = ct.ahsv.hue == USHRT_MAX ? qreal(-1.0) : ct.ahsv.hue / qreal(36000.0);
605 *s = ct.ahsv.saturation / qreal(USHRT_MAX);
606 *v = ct.ahsv.value / qreal(USHRT_MAX);
609 *a = ct.ahsv.alpha / qreal(USHRT_MAX);
613 Sets the contents pointed to by \a h, \a s, \a v, and \a a, to the hue,
614 saturation, value, and alpha-channel (transparency) components of the
617 These components can be retrieved individually using the hue(),
618 saturation(), value() and alpha() functions.
620 \sa setHsv(), {QColor#The HSV Color Model}{The HSV Color Model}
622 void QColor::getHsv(int *h, int *s, int *v, int *a) const
627 if (cspec != Invalid && cspec != Hsv) {
628 toHsv().getHsv(h, s, v, a);
632 *h = ct.ahsv.hue == USHRT_MAX ? -1 : ct.ahsv.hue / 100;
633 *s = ct.ahsv.saturation >> 8;
634 *v = ct.ahsv.value >> 8;
637 *a = ct.ahsv.alpha >> 8;
641 Sets a HSV color value; \a h is the hue, \a s is the saturation, \a v is
642 the value and \a a is the alpha component of the HSV color.
644 All the values must be in the range 0.0-1.0.
646 \sa getHsvF(), setHsv(), {QColor#The HSV Color Model}{The HSV Color Model}
648 void QColor::setHsvF(qreal h, qreal s, qreal v, qreal a)
650 if (((h < qreal(0.0) || h > qreal(1.0)) && h != qreal(-1.0))
651 || (s < qreal(0.0) || s > qreal(1.0))
652 || (v < qreal(0.0) || v > qreal(1.0))
653 || (a < qreal(0.0) || a > qreal(1.0))) {
654 qWarning("QColor::setHsvF: HSV parameters out of range");
659 ct.ahsv.alpha = qRound(a * USHRT_MAX);
660 ct.ahsv.hue = h == qreal(-1.0) ? USHRT_MAX : qRound(h * 36000);
661 ct.ahsv.saturation = qRound(s * USHRT_MAX);
662 ct.ahsv.value = qRound(v * USHRT_MAX);
667 Sets a HSV color value; \a h is the hue, \a s is the saturation, \a v is
668 the value and \a a is the alpha component of the HSV color.
670 The saturation, value and alpha-channel values must be in the range 0-255,
671 and the hue value must be greater than -1.
673 \sa getHsv(), setHsvF(), {QColor#The HSV Color Model}{The HSV Color Model}
675 void QColor::setHsv(int h, int s, int v, int a)
677 if (h < -1 || (uint)s > 255 || (uint)v > 255 || (uint)a > 255) {
678 qWarning("QColor::setHsv: HSV parameters out of range");
684 ct.ahsv.alpha = a * 0x101;
685 ct.ahsv.hue = h == -1 ? USHRT_MAX : (h % 360) * 100;
686 ct.ahsv.saturation = s * 0x101;
687 ct.ahsv.value = v * 0x101;
694 Sets the contents pointed to by \a h, \a s, \a l, and \a a, to the hue,
695 saturation, lightness, and alpha-channel (transparency) components of the
698 These components can be retrieved individually using the hueHslF(),
699 saturationHslF(), lightnessF() and alphaF() functions.
703 void QColor::getHslF(qreal *h, qreal *s, qreal *l, qreal *a) const
708 if (cspec != Invalid && cspec != Hsl) {
709 toHsl().getHslF(h, s, l, a);
713 *h = ct.ahsl.hue == USHRT_MAX ? qreal(-1.0) : ct.ahsl.hue / qreal(36000.0);
714 *s = ct.ahsl.saturation / qreal(USHRT_MAX);
715 *l = ct.ahsl.lightness / qreal(USHRT_MAX);
718 *a = ct.ahsl.alpha / qreal(USHRT_MAX);
724 Sets the contents pointed to by \a h, \a s, \a l, and \a a, to the hue,
725 saturation, lightness, and alpha-channel (transparency) components of the
728 These components can be retrieved individually using the hueHsl(),
729 saturationHsl(), lightness() and alpha() functions.
733 void QColor::getHsl(int *h, int *s, int *l, int *a) const
738 if (cspec != Invalid && cspec != Hsl) {
739 toHsl().getHsl(h, s, l, a);
743 *h = ct.ahsl.hue == USHRT_MAX ? -1 : ct.ahsl.hue / 100;
744 *s = ct.ahsl.saturation >> 8;
745 *l = ct.ahsl.lightness >> 8;
748 *a = ct.ahsl.alpha >> 8;
754 Sets a HSL color lightness; \a h is the hue, \a s is the saturation, \a l is
755 the lightness and \a a is the alpha component of the HSL color.
757 All the values must be in the range 0.0-1.0.
759 \sa getHslF(), setHsl()
761 void QColor::setHslF(qreal h, qreal s, qreal l, qreal a)
763 if (((h < qreal(0.0) || h > qreal(1.0)) && h != qreal(-1.0))
764 || (s < qreal(0.0) || s > qreal(1.0))
765 || (l < qreal(0.0) || l > qreal(1.0))
766 || (a < qreal(0.0) || a > qreal(1.0))) {
767 qWarning("QColor::setHsvF: HSV parameters out of range");
772 ct.ahsl.alpha = qRound(a * USHRT_MAX);
773 ct.ahsl.hue = h == qreal(-1.0) ? USHRT_MAX : qRound(h * 36000);
774 ct.ahsl.saturation = qRound(s * USHRT_MAX);
775 ct.ahsl.lightness = qRound(l * USHRT_MAX);
782 Sets a HSL color value; \a h is the hue, \a s is the saturation, \a l is
783 the lightness and \a a is the alpha component of the HSL color.
785 The saturation, value and alpha-channel values must be in the range 0-255,
786 and the hue value must be greater than -1.
788 \sa getHsl(), setHslF()
790 void QColor::setHsl(int h, int s, int l, int a)
792 if (h < -1 || (uint)s > 255 || (uint)l > 255 || (uint)a > 255) {
793 qWarning("QColor::setHsv: HSV parameters out of range");
799 ct.ahsl.alpha = a * 0x101;
800 ct.ahsl.hue = h == -1 ? USHRT_MAX : (h % 360) * 100;
801 ct.ahsl.saturation = s * 0x101;
802 ct.ahsl.lightness = l * 0x101;
807 Sets the contents pointed to by \a r, \a g, \a b, and \a a, to the red,
808 green, blue, and alpha-channel (transparency) components of the color's
811 These components can be retrieved individually using the redF(), greenF(),
812 blueF() and alphaF() functions.
816 void QColor::getRgbF(qreal *r, qreal *g, qreal *b, qreal *a) const
821 if (cspec != Invalid && cspec != Rgb) {
822 toRgb().getRgbF(r, g, b, a);
826 *r = ct.argb.red / qreal(USHRT_MAX);
827 *g = ct.argb.green / qreal(USHRT_MAX);
828 *b = ct.argb.blue / qreal(USHRT_MAX);
831 *a = ct.argb.alpha / qreal(USHRT_MAX);
836 Sets the contents pointed to by \a r, \a g, \a b, and \a a, to the red,
837 green, blue, and alpha-channel (transparency) components of the color's
840 These components can be retrieved individually using the red(), green(),
841 blue() and alpha() functions.
845 void QColor::getRgb(int *r, int *g, int *b, int *a) const
850 if (cspec != Invalid && cspec != Rgb) {
851 toRgb().getRgb(r, g, b, a);
855 *r = ct.argb.red >> 8;
856 *g = ct.argb.green >> 8;
857 *b = ct.argb.blue >> 8;
860 *a = ct.argb.alpha >> 8;
864 \fn void QColor::setRgbF(qreal r, qreal g, qreal b, qreal a)
866 Sets the color channels of this color to \a r (red), \a g (green),
867 \a b (blue) and \a a (alpha, transparency).
869 All values must be in the range 0.0-1.0.
871 \sa rgb(), getRgbF(), setRgb()
873 void QColor::setRgbF(qreal r, qreal g, qreal b, qreal a)
875 if (r < qreal(0.0) || r > qreal(1.0)
876 || g < qreal(0.0) || g > qreal(1.0)
877 || b < qreal(0.0) || b > qreal(1.0)
878 || a < qreal(0.0) || a > qreal(1.0)) {
879 qWarning("QColor::setRgbF: RGB parameters out of range");
885 ct.argb.alpha = qRound(a * USHRT_MAX);
886 ct.argb.red = qRound(r * USHRT_MAX);
887 ct.argb.green = qRound(g * USHRT_MAX);
888 ct.argb.blue = qRound(b * USHRT_MAX);
893 Sets the RGB value to \a r, \a g, \a b and the alpha value to \a a.
895 All the values must be in the range 0-255.
897 \sa rgb(), getRgb(), setRgbF()
899 void QColor::setRgb(int r, int g, int b, int a)
901 if ((uint)r > 255 || (uint)g > 255 || (uint)b > 255 || (uint)a > 255) {
902 qWarning("QColor::setRgb: RGB parameters out of range");
908 ct.argb.alpha = a * 0x101;
909 ct.argb.red = r * 0x101;
910 ct.argb.green = g * 0x101;
911 ct.argb.blue = b * 0x101;
916 \fn QRgb QColor::rgba() const
918 Returns the RGB value of the color, including its alpha.
920 For an invalid color, the alpha value of the returned color is unspecified.
925 QRgb QColor::rgba() const
927 if (cspec != Invalid && cspec != Rgb)
928 return toRgb().rgba();
929 return qRgba(ct.argb.red >> 8, ct.argb.green >> 8, ct.argb.blue >> 8, ct.argb.alpha >> 8);
933 Sets the RGB value to \a rgba, including its alpha.
937 void QColor::setRgba(QRgb rgba)
940 ct.argb.alpha = qAlpha(rgba) * 0x101;
941 ct.argb.red = qRed(rgba) * 0x101;
942 ct.argb.green = qGreen(rgba) * 0x101;
943 ct.argb.blue = qBlue(rgba) * 0x101;
948 \fn QRgb QColor::rgb() const
950 Returns the RGB value of the color. The alpha value is opaque.
954 QRgb QColor::rgb() const
956 if (cspec != Invalid && cspec != Rgb)
957 return toRgb().rgb();
958 return qRgb(ct.argb.red >> 8, ct.argb.green >> 8, ct.argb.blue >> 8);
964 Sets the RGB value to \a rgb. The alpha value is set to opaque.
966 void QColor::setRgb(QRgb rgb)
969 ct.argb.alpha = 0xffff;
970 ct.argb.red = qRed(rgb) * 0x101;
971 ct.argb.green = qGreen(rgb) * 0x101;
972 ct.argb.blue = qBlue(rgb) * 0x101;
977 Returns the alpha color component of this color.
979 \sa setAlpha(), alphaF(), {QColor#Alpha-Blended Drawing}{Alpha-Blended Drawing}
981 int QColor::alpha() const
982 { return ct.argb.alpha >> 8; }
986 Sets the alpha of this color to \a alpha. Integer alpha is specified in the
989 \sa alpha(), alphaF(), {QColor#Alpha-Blended Drawing}{Alpha-Blended Drawing}
992 void QColor::setAlpha(int alpha)
994 QCOLOR_INT_RANGE_CHECK("QColor::setAlpha", alpha);
995 ct.argb.alpha = alpha * 0x101;
999 Returns the alpha color component of this color.
1001 \sa setAlphaF(), alpha(), {QColor#Alpha-Blended Drawing}{Alpha-Blended Drawing}
1003 qreal QColor::alphaF() const
1004 { return ct.argb.alpha / qreal(USHRT_MAX); }
1007 Sets the alpha of this color to \a alpha. qreal alpha is specified in the
1010 \sa alphaF(), alpha(), {QColor#Alpha-Blended Drawing}{Alpha-Blended Drawing}
1013 void QColor::setAlphaF(qreal alpha)
1015 QCOLOR_REAL_RANGE_CHECK("QColor::setAlphaF", alpha);
1016 qreal tmp = alpha * USHRT_MAX;
1017 ct.argb.alpha = qRound(tmp);
1022 Returns the red color component of this color.
1024 \sa setRed(), redF(), getRgb()
1026 int QColor::red() const
1028 if (cspec != Invalid && cspec != Rgb)
1029 return toRgb().red();
1030 return ct.argb.red >> 8;
1034 Sets the red color component of this color to \a red. Integer components
1035 are specified in the range 0-255.
1037 \sa red(), redF(), setRgb()
1039 void QColor::setRed(int red)
1041 QCOLOR_INT_RANGE_CHECK("QColor::setRed", red);
1043 setRgb(red, green(), blue(), alpha());
1045 ct.argb.red = red * 0x101;
1049 Returns the green color component of this color.
1051 \sa setGreen(), greenF(), getRgb()
1053 int QColor::green() const
1055 if (cspec != Invalid && cspec != Rgb)
1056 return toRgb().green();
1057 return ct.argb.green >> 8;
1061 Sets the green color component of this color to \a green. Integer
1062 components are specified in the range 0-255.
1064 \sa green(), greenF(), setRgb()
1066 void QColor::setGreen(int green)
1068 QCOLOR_INT_RANGE_CHECK("QColor::setGreen", green);
1070 setRgb(red(), green, blue(), alpha());
1072 ct.argb.green = green * 0x101;
1077 Returns the blue color component of this color.
1079 \sa setBlue(), blueF(), getRgb()
1081 int QColor::blue() const
1083 if (cspec != Invalid && cspec != Rgb)
1084 return toRgb().blue();
1085 return ct.argb.blue >> 8;
1090 Sets the blue color component of this color to \a blue. Integer components
1091 are specified in the range 0-255.
1093 \sa blue(), blueF(), setRgb()
1095 void QColor::setBlue(int blue)
1097 QCOLOR_INT_RANGE_CHECK("QColor::setBlue", blue);
1099 setRgb(red(), green(), blue, alpha());
1101 ct.argb.blue = blue * 0x101;
1105 Returns the red color component of this color.
1107 \sa setRedF(), red(), getRgbF()
1109 qreal QColor::redF() const
1111 if (cspec != Invalid && cspec != Rgb)
1112 return toRgb().redF();
1113 return ct.argb.red / qreal(USHRT_MAX);
1118 Sets the red color component of this color to \a red. Float components
1119 are specified in the range 0.0-1.0.
1121 \sa redF(), red(), setRgbF()
1123 void QColor::setRedF(qreal red)
1125 QCOLOR_REAL_RANGE_CHECK("QColor::setRedF", red);
1127 setRgbF(red, greenF(), blueF(), alphaF());
1129 ct.argb.red = qRound(red * USHRT_MAX);
1133 Returns the green color component of this color.
1135 \sa setGreenF(), green(), getRgbF()
1137 qreal QColor::greenF() const
1139 if (cspec != Invalid && cspec != Rgb)
1140 return toRgb().greenF();
1141 return ct.argb.green / qreal(USHRT_MAX);
1146 Sets the green color component of this color to \a green. Float components
1147 are specified in the range 0.0-1.0.
1149 \sa greenF(), green(), setRgbF()
1151 void QColor::setGreenF(qreal green)
1153 QCOLOR_REAL_RANGE_CHECK("QColor::setGreenF", green);
1155 setRgbF(redF(), green, blueF(), alphaF());
1157 ct.argb.green = qRound(green * USHRT_MAX);
1161 Returns the blue color component of this color.
1163 \sa setBlueF(), blue(), getRgbF()
1165 qreal QColor::blueF() const
1167 if (cspec != Invalid && cspec != Rgb)
1168 return toRgb().blueF();
1169 return ct.argb.blue / qreal(USHRT_MAX);
1173 Sets the blue color component of this color to \a blue. Float components
1174 are specified in the range 0.0-1.0.
1176 \sa blueF(), blue(), setRgbF()
1178 void QColor::setBlueF(qreal blue)
1180 QCOLOR_REAL_RANGE_CHECK("QColor::setBlueF", blue);
1182 setRgbF(redF(), greenF(), blue, alphaF());
1184 ct.argb.blue = qRound(blue * USHRT_MAX);
1188 Returns the hue color component of this color.
1190 The color is implicitly converted to HSV.
1192 \sa hsvHue(), hueF(), getHsv(), {QColor#The HSV Color Model}{The HSV Color Model}
1195 int QColor::hue() const
1201 Returns the hue color component of this color.
1203 \sa hueF(), getHsv(), {QColor#The HSV Color Model}{The HSV Color Model}
1205 int QColor::hsvHue() const
1207 if (cspec != Invalid && cspec != Hsv)
1208 return toHsv().hue();
1209 return ct.ahsv.hue == USHRT_MAX ? -1 : ct.ahsv.hue / 100;
1213 Returns the saturation color component of this color.
1215 The color is implicitly converted to HSV.
1217 \sa hsvSaturation(), saturationF(), getHsv(), {QColor#The HSV Color Model}{The HSV Color
1221 int QColor::saturation() const
1223 return hsvSaturation();
1227 Returns the saturation color component of this color.
1229 \sa saturationF(), getHsv(), {QColor#The HSV Color Model}{The HSV Color Model}
1231 int QColor::hsvSaturation() const
1233 if (cspec != Invalid && cspec != Hsv)
1234 return toHsv().saturation();
1235 return ct.ahsv.saturation >> 8;
1239 Returns the value color component of this color.
1241 \sa valueF(), getHsv(), {QColor#The HSV Color Model}{The HSV Color Model}
1243 int QColor::value() const
1245 if (cspec != Invalid && cspec != Hsv)
1246 return toHsv().value();
1247 return ct.ahsv.value >> 8;
1251 Returns the hue color component of this color.
1253 The color is implicitly converted to HSV.
1255 \sa hsvHueF(), hue(), getHsvF(), {QColor#The HSV Color Model}{The HSV Color Model}
1257 qreal QColor::hueF() const
1263 Returns the hue color component of this color.
1265 \sa hue(), getHsvF(), {QColor#The HSV Color Model}{The HSV Color
1268 qreal QColor::hsvHueF() const
1270 if (cspec != Invalid && cspec != Hsv)
1271 return toHsv().hueF();
1272 return ct.ahsv.hue == USHRT_MAX ? qreal(-1.0) : ct.ahsv.hue / qreal(36000.0);
1276 Returns the saturation color component of this color.
1278 The color is implicitly converted to HSV.
1280 \sa hsvSaturationF(), saturation(), getHsvF(), {QColor#The HSV Color Model}{The HSV Color
1283 qreal QColor::saturationF() const
1285 return hsvSaturationF();
1289 Returns the saturation color component of this color.
1291 \sa saturation(), getHsvF(), {QColor#The HSV Color Model}{The HSV Color Model}
1293 qreal QColor::hsvSaturationF() const
1295 if (cspec != Invalid && cspec != Hsv)
1296 return toHsv().saturationF();
1297 return ct.ahsv.saturation / qreal(USHRT_MAX);
1301 Returns the value color component of this color.
1303 \sa value(), getHsvF(), {QColor#The HSV Color Model}{The HSV Color Model}
1305 qreal QColor::valueF() const
1307 if (cspec != Invalid && cspec != Hsv)
1308 return toHsv().valueF();
1309 return ct.ahsv.value / qreal(USHRT_MAX);
1315 Returns the hue color component of this color.
1317 \sa getHslF(), getHsl()
1319 int QColor::hslHue() const
1321 if (cspec != Invalid && cspec != Hsl)
1322 return toHsl().hslHue();
1323 return ct.ahsl.hue == USHRT_MAX ? -1 : ct.ahsl.hue / 100;
1329 Returns the saturation color component of this color.
1331 \sa saturationF(), getHsv(), {QColor#The HSV Color Model}{The HSV Color Model}
1333 int QColor::hslSaturation() const
1335 if (cspec != Invalid && cspec != Hsl)
1336 return toHsl().hslSaturation();
1337 return ct.ahsl.saturation >> 8;
1343 Returns the lightness color component of this color.
1345 \sa lightnessF(), getHsl()
1347 int QColor::lightness() const
1349 if (cspec != Invalid && cspec != Hsl)
1350 return toHsl().lightness();
1351 return ct.ahsl.lightness >> 8;
1357 Returns the hue color component of this color.
1359 \sa hue(), getHslF()
1361 qreal QColor::hslHueF() const
1363 if (cspec != Invalid && cspec != Hsl)
1364 return toHsl().hslHueF();
1365 return ct.ahsl.hue == USHRT_MAX ? qreal(-1.0) : ct.ahsl.hue / qreal(36000.0);
1371 Returns the saturation color component of this color.
1373 \sa saturationF(), getHslF()
1375 qreal QColor::hslSaturationF() const
1377 if (cspec != Invalid && cspec != Hsl)
1378 return toHsl().hslSaturationF();
1379 return ct.ahsl.saturation / qreal(USHRT_MAX);
1385 Returns the lightness color component of this color.
1387 \sa value(), getHslF()
1389 qreal QColor::lightnessF() const
1391 if (cspec != Invalid && cspec != Hsl)
1392 return toHsl().lightnessF();
1393 return ct.ahsl.lightness / qreal(USHRT_MAX);
1397 Returns the cyan color component of this color.
1399 \sa cyanF(), getCmyk(), {QColor#The CMYK Color Model}{The CMYK Color Model}
1401 int QColor::cyan() const
1403 if (cspec != Invalid && cspec != Cmyk)
1404 return toCmyk().cyan();
1405 return ct.acmyk.cyan >> 8;
1409 Returns the magenta color component of this color.
1411 \sa magentaF(), getCmyk(), {QColor#The CMYK Color Model}{The CMYK Color Model}
1413 int QColor::magenta() const
1415 if (cspec != Invalid && cspec != Cmyk)
1416 return toCmyk().magenta();
1417 return ct.acmyk.magenta >> 8;
1421 Returns the yellow color component of this color.
1423 \sa yellowF(), getCmyk(), {QColor#The CMYK Color Model}{The CMYK Color Model}
1425 int QColor::yellow() const
1427 if (cspec != Invalid && cspec != Cmyk)
1428 return toCmyk().yellow();
1429 return ct.acmyk.yellow >> 8;
1433 Returns the black color component of this color.
1435 \sa blackF(), getCmyk(), {QColor#The CMYK Color Model}{The CMYK Color Model}
1438 int QColor::black() const
1440 if (cspec != Invalid && cspec != Cmyk)
1441 return toCmyk().black();
1442 return ct.acmyk.black >> 8;
1446 Returns the cyan color component of this color.
1448 \sa cyan(), getCmykF(), {QColor#The CMYK Color Model}{The CMYK Color Model}
1450 qreal QColor::cyanF() const
1452 if (cspec != Invalid && cspec != Cmyk)
1453 return toCmyk().cyanF();
1454 return ct.acmyk.cyan / qreal(USHRT_MAX);
1458 Returns the magenta color component of this color.
1460 \sa magenta(), getCmykF(), {QColor#The CMYK Color Model}{The CMYK Color Model}
1462 qreal QColor::magentaF() const
1464 if (cspec != Invalid && cspec != Cmyk)
1465 return toCmyk().magentaF();
1466 return ct.acmyk.magenta / qreal(USHRT_MAX);
1470 Returns the yellow color component of this color.
1472 \sa yellow(), getCmykF(), {QColor#The CMYK Color Model}{The CMYK Color Model}
1474 qreal QColor::yellowF() const
1476 if (cspec != Invalid && cspec != Cmyk)
1477 return toCmyk().yellowF();
1478 return ct.acmyk.yellow / qreal(USHRT_MAX);
1482 Returns the black color component of this color.
1484 \sa black(), getCmykF(), {QColor#The CMYK Color Model}{The CMYK Color Model}
1486 qreal QColor::blackF() const
1488 if (cspec != Invalid && cspec != Cmyk)
1489 return toCmyk().blackF();
1490 return ct.acmyk.black / qreal(USHRT_MAX);
1494 Create and returns an RGB QColor based on this color.
1496 \sa fromRgb(), convertTo(), isValid()
1498 QColor QColor::toRgb() const
1500 if (!isValid() || cspec == Rgb)
1505 color.ct.argb.alpha = ct.argb.alpha;
1506 color.ct.argb.pad = 0;
1511 if (ct.ahsv.saturation == 0 || ct.ahsv.hue == USHRT_MAX) {
1513 color.ct.argb.red = color.ct.argb.green = color.ct.argb.blue = ct.ahsv.value;
1518 const qreal h = ct.ahsv.hue == 36000 ? 0 : ct.ahsv.hue / 6000.;
1519 const qreal s = ct.ahsv.saturation / qreal(USHRT_MAX);
1520 const qreal v = ct.ahsv.value / qreal(USHRT_MAX);
1521 const int i = int(h);
1522 const qreal f = h - i;
1523 const qreal p = v * (qreal(1.0) - s);
1526 const qreal q = v * (qreal(1.0) - (s * f));
1530 color.ct.argb.red = qRound(q * USHRT_MAX);
1531 color.ct.argb.green = qRound(v * USHRT_MAX);
1532 color.ct.argb.blue = qRound(p * USHRT_MAX);
1535 color.ct.argb.red = qRound(p * USHRT_MAX);
1536 color.ct.argb.green = qRound(q * USHRT_MAX);
1537 color.ct.argb.blue = qRound(v * USHRT_MAX);
1540 color.ct.argb.red = qRound(v * USHRT_MAX);
1541 color.ct.argb.green = qRound(p * USHRT_MAX);
1542 color.ct.argb.blue = qRound(q * USHRT_MAX);
1546 const qreal t = v * (qreal(1.0) - (s * (qreal(1.0) - f)));
1550 color.ct.argb.red = qRound(v * USHRT_MAX);
1551 color.ct.argb.green = qRound(t * USHRT_MAX);
1552 color.ct.argb.blue = qRound(p * USHRT_MAX);
1555 color.ct.argb.red = qRound(p * USHRT_MAX);
1556 color.ct.argb.green = qRound(v * USHRT_MAX);
1557 color.ct.argb.blue = qRound(t * USHRT_MAX);
1560 color.ct.argb.red = qRound(t * USHRT_MAX);
1561 color.ct.argb.green = qRound(p * USHRT_MAX);
1562 color.ct.argb.blue = qRound(v * USHRT_MAX);
1570 if (ct.ahsl.saturation == 0 || ct.ahsl.hue == USHRT_MAX) {
1572 color.ct.argb.red = color.ct.argb.green = color.ct.argb.blue = ct.ahsl.lightness;
1573 } else if (ct.ahsl.lightness == 0) {
1575 color.ct.argb.red = color.ct.argb.green = color.ct.argb.blue = 0;
1578 const qreal h = ct.ahsl.hue == 36000 ? 0 : ct.ahsl.hue / 36000.;
1579 const qreal s = ct.ahsl.saturation / qreal(USHRT_MAX);
1580 const qreal l = ct.ahsl.lightness / qreal(USHRT_MAX);
1584 temp2 = l * (qreal(1.0) + s);
1586 temp2 = l + s - (l * s);
1588 const qreal temp1 = (qreal(2.0) * l) - temp2;
1589 qreal temp3[3] = { h + (qreal(1.0) / qreal(3.0)),
1591 h - (qreal(1.0) / qreal(3.0)) };
1593 for (int i = 0; i != 3; ++i) {
1594 if (temp3[i] < qreal(0.0))
1595 temp3[i] += qreal(1.0);
1596 else if (temp3[i] > qreal(1.0))
1597 temp3[i] -= qreal(1.0);
1599 const qreal sixtemp3 = temp3[i] * qreal(6.0);
1600 if (sixtemp3 < qreal(1.0))
1601 color.ct.array[i+1] = qRound((temp1 + (temp2 - temp1) * sixtemp3) * USHRT_MAX);
1602 else if ((temp3[i] * qreal(2.0)) < qreal(1.0))
1603 color.ct.array[i+1] = qRound(temp2 * USHRT_MAX);
1604 else if ((temp3[i] * qreal(3.0)) < qreal(2.0))
1605 color.ct.array[i+1] = qRound((temp1 + (temp2 -temp1) * (qreal(2.0) /qreal(3.0) - temp3[i]) * qreal(6.0)) * USHRT_MAX);
1607 color.ct.array[i+1] = qRound(temp1 * USHRT_MAX);
1609 color.ct.argb.red = color.ct.argb.red == 1 ? 0 : color.ct.argb.red;
1610 color.ct.argb.green = color.ct.argb.green == 1 ? 0 : color.ct.argb.green;
1611 color.ct.argb.blue = color.ct.argb.blue == 1 ? 0 : color.ct.argb.blue;
1617 const qreal c = ct.acmyk.cyan / qreal(USHRT_MAX);
1618 const qreal m = ct.acmyk.magenta / qreal(USHRT_MAX);
1619 const qreal y = ct.acmyk.yellow / qreal(USHRT_MAX);
1620 const qreal k = ct.acmyk.black / qreal(USHRT_MAX);
1622 color.ct.argb.red = qRound((qreal(1.0) - (c * (qreal(1.0) - k) + k)) * USHRT_MAX);
1623 color.ct.argb.green = qRound((qreal(1.0) - (m * (qreal(1.0) - k) + k)) * USHRT_MAX);
1624 color.ct.argb.blue = qRound((qreal(1.0) - (y * (qreal(1.0) - k) + k)) * USHRT_MAX);
1635 #define Q_MAX_3(a, b, c) ( ( a > b && a > c) ? a : (b > c ? b : c) )
1636 #define Q_MIN_3(a, b, c) ( ( a < b && a < c) ? a : (b < c ? b : c) )
1640 Creates and returns an HSV QColor based on this color.
1642 \sa fromHsv(), convertTo(), isValid(), {QColor#The HSV Color Model}{The HSV Color Model}
1644 QColor QColor::toHsv() const
1646 if (!isValid() || cspec == Hsv)
1650 return toRgb().toHsv();
1654 color.ct.ahsv.alpha = ct.argb.alpha;
1655 color.ct.ahsv.pad = 0;
1657 const qreal r = ct.argb.red / qreal(USHRT_MAX);
1658 const qreal g = ct.argb.green / qreal(USHRT_MAX);
1659 const qreal b = ct.argb.blue / qreal(USHRT_MAX);
1660 const qreal max = Q_MAX_3(r, g, b);
1661 const qreal min = Q_MIN_3(r, g, b);
1662 const qreal delta = max - min;
1663 color.ct.ahsv.value = qRound(max * USHRT_MAX);
1664 if (qFuzzyIsNull(delta)) {
1665 // achromatic case, hue is undefined
1666 color.ct.ahsv.hue = USHRT_MAX;
1667 color.ct.ahsv.saturation = 0;
1671 color.ct.ahsv.saturation = qRound((delta / max) * USHRT_MAX);
1672 if (qFuzzyCompare(r, max)) {
1673 hue = ((g - b) /delta);
1674 } else if (qFuzzyCompare(g, max)) {
1675 hue = (qreal(2.0) + (b - r) / delta);
1676 } else if (qFuzzyCompare(b, max)) {
1677 hue = (qreal(4.0) + (r - g) / delta);
1679 Q_ASSERT_X(false, "QColor::toHsv", "internal error");
1682 if (hue < qreal(0.0))
1683 hue += qreal(360.0);
1684 color.ct.ahsv.hue = qRound(hue * 100);
1691 Creates and returns an HSL QColor based on this color.
1693 \sa fromHsl(), convertTo(), isValid()
1695 QColor QColor::toHsl() const
1697 if (!isValid() || cspec == Hsl)
1701 return toRgb().toHsl();
1705 color.ct.ahsl.alpha = ct.argb.alpha;
1706 color.ct.ahsl.pad = 0;
1708 const qreal r = ct.argb.red / qreal(USHRT_MAX);
1709 const qreal g = ct.argb.green / qreal(USHRT_MAX);
1710 const qreal b = ct.argb.blue / qreal(USHRT_MAX);
1711 const qreal max = Q_MAX_3(r, g, b);
1712 const qreal min = Q_MIN_3(r, g, b);
1713 const qreal delta = max - min;
1714 const qreal delta2 = max + min;
1715 const qreal lightness = qreal(0.5) * delta2;
1716 color.ct.ahsl.lightness = qRound(lightness * USHRT_MAX);
1717 if (qFuzzyIsNull(delta)) {
1718 // achromatic case, hue is undefined
1719 color.ct.ahsl.hue = USHRT_MAX;
1720 color.ct.ahsl.saturation = 0;
1724 if (lightness < qreal(0.5))
1725 color.ct.ahsl.saturation = qRound((delta / delta2) * USHRT_MAX);
1727 color.ct.ahsl.saturation = qRound((delta / (qreal(2.0) - delta2)) * USHRT_MAX);
1728 if (qFuzzyCompare(r, max)) {
1729 hue = ((g - b) /delta);
1730 } else if (qFuzzyCompare(g, max)) {
1731 hue = (qreal(2.0) + (b - r) / delta);
1732 } else if (qFuzzyCompare(b, max)) {
1733 hue = (qreal(4.0) + (r - g) / delta);
1735 Q_ASSERT_X(false, "QColor::toHsv", "internal error");
1738 if (hue < qreal(0.0))
1739 hue += qreal(360.0);
1740 color.ct.ahsl.hue = qRound(hue * 100);
1747 Creates and returns a CMYK QColor based on this color.
1749 \sa fromCmyk(), convertTo(), isValid(), {QColor#The CMYK Color Model}{The CMYK Color Model}
1751 QColor QColor::toCmyk() const
1753 if (!isValid() || cspec == Cmyk)
1756 return toRgb().toCmyk();
1760 color.ct.acmyk.alpha = ct.argb.alpha;
1763 const qreal r = ct.argb.red / qreal(USHRT_MAX);
1764 const qreal g = ct.argb.green / qreal(USHRT_MAX);
1765 const qreal b = ct.argb.blue / qreal(USHRT_MAX);
1766 qreal c = qreal(1.0) - r;
1767 qreal m = qreal(1.0) - g;
1768 qreal y = qreal(1.0) - b;
1771 const qreal k = qMin(c, qMin(m, y));
1773 if (!qFuzzyIsNull(k - 1)) {
1774 c = (c - k) / (qreal(1.0) - k);
1775 m = (m - k) / (qreal(1.0) - k);
1776 y = (y - k) / (qreal(1.0) - k);
1779 color.ct.acmyk.cyan = qRound(c * USHRT_MAX);
1780 color.ct.acmyk.magenta = qRound(m * USHRT_MAX);
1781 color.ct.acmyk.yellow = qRound(y * USHRT_MAX);
1782 color.ct.acmyk.black = qRound(k * USHRT_MAX);
1787 QColor QColor::convertTo(QColor::Spec colorSpec) const
1789 if (colorSpec == cspec)
1791 switch (colorSpec) {
1803 return QColor(); // must be invalid
1808 Static convenience function that returns a QColor constructed from the
1809 given QRgb value \a rgb.
1811 The alpha component of \a rgb is ignored (i.e. it is automatically set to
1812 255), use the fromRgba() function to include the alpha-channel specified by
1813 the given QRgb value.
1815 \sa fromRgba(), fromRgbF(), toRgb(), isValid()
1818 QColor QColor::fromRgb(QRgb rgb)
1820 return fromRgb(qRed(rgb), qGreen(rgb), qBlue(rgb));
1825 Static convenience function that returns a QColor constructed from the
1826 given QRgb value \a rgba.
1828 Unlike the fromRgb() function, the alpha-channel specified by the given
1829 QRgb value is included.
1831 \sa fromRgb(), isValid()
1834 QColor QColor::fromRgba(QRgb rgba)
1836 return fromRgb(qRed(rgba), qGreen(rgba), qBlue(rgba), qAlpha(rgba));
1840 Static convenience function that returns a QColor constructed from the RGB
1841 color values, \a r (red), \a g (green), \a b (blue), and \a a
1842 (alpha-channel, i.e. transparency).
1844 All the values must be in the range 0-255.
1846 \sa toRgb(), fromRgbF(), isValid()
1848 QColor QColor::fromRgb(int r, int g, int b, int a)
1850 if (r < 0 || r > 255
1853 || a < 0 || a > 255) {
1854 qWarning("QColor::fromRgb: RGB parameters out of range");
1860 color.ct.argb.alpha = a * 0x101;
1861 color.ct.argb.red = r * 0x101;
1862 color.ct.argb.green = g * 0x101;
1863 color.ct.argb.blue = b * 0x101;
1864 color.ct.argb.pad = 0;
1869 Static convenience function that returns a QColor constructed from the RGB
1870 color values, \a r (red), \a g (green), \a b (blue), and \a a
1871 (alpha-channel, i.e. transparency).
1873 All the values must be in the range 0.0-1.0.
1875 \sa fromRgb(), toRgb(), isValid()
1877 QColor QColor::fromRgbF(qreal r, qreal g, qreal b, qreal a)
1879 if (r < qreal(0.0) || r > qreal(1.0)
1880 || g < qreal(0.0) || g > qreal(1.0)
1881 || b < qreal(0.0) || b > qreal(1.0)
1882 || a < qreal(0.0) || a > qreal(1.0)) {
1883 qWarning("QColor::fromRgbF: RGB parameters out of range");
1889 color.ct.argb.alpha = qRound(a * USHRT_MAX);
1890 color.ct.argb.red = qRound(r * USHRT_MAX);
1891 color.ct.argb.green = qRound(g * USHRT_MAX);
1892 color.ct.argb.blue = qRound(b * USHRT_MAX);
1893 color.ct.argb.pad = 0;
1898 Static convenience function that returns a QColor constructed from the HSV
1899 color values, \a h (hue), \a s (saturation), \a v (value), and \a a
1900 (alpha-channel, i.e. transparency).
1902 The value of \a s, \a v, and \a a must all be in the range 0-255; the value
1903 of \a h must be in the range 0-359.
1905 \sa toHsv(), fromHsvF(), isValid(), {QColor#The HSV Color Model}{The HSV Color Model}
1907 QColor QColor::fromHsv(int h, int s, int v, int a)
1909 if (((h < 0 || h >= 360) && h != -1)
1912 || a < 0 || a > 255) {
1913 qWarning("QColor::fromHsv: HSV parameters out of range");
1919 color.ct.ahsv.alpha = a * 0x101;
1920 color.ct.ahsv.hue = h == -1 ? USHRT_MAX : (h % 360) * 100;
1921 color.ct.ahsv.saturation = s * 0x101;
1922 color.ct.ahsv.value = v * 0x101;
1923 color.ct.ahsv.pad = 0;
1930 Static convenience function that returns a QColor constructed from the HSV
1931 color values, \a h (hue), \a s (saturation), \a v (value), and \a a
1932 (alpha-channel, i.e. transparency).
1934 All the values must be in the range 0.0-1.0.
1936 \sa toHsv(), fromHsv(), isValid(), {QColor#The HSV Color Model}{The HSV Color Model}
1938 QColor QColor::fromHsvF(qreal h, qreal s, qreal v, qreal a)
1940 if (((h < qreal(0.0) || h > qreal(1.0)) && h != qreal(-1.0))
1941 || (s < qreal(0.0) || s > qreal(1.0))
1942 || (v < qreal(0.0) || v > qreal(1.0))
1943 || (a < qreal(0.0) || a > qreal(1.0))) {
1944 qWarning("QColor::fromHsvF: HSV parameters out of range");
1950 color.ct.ahsv.alpha = qRound(a * USHRT_MAX);
1951 color.ct.ahsv.hue = h == qreal(-1.0) ? USHRT_MAX : qRound(h * 36000);
1952 color.ct.ahsv.saturation = qRound(s * USHRT_MAX);
1953 color.ct.ahsv.value = qRound(v * USHRT_MAX);
1954 color.ct.ahsv.pad = 0;
1961 Static convenience function that returns a QColor constructed from the HSV
1962 color values, \a h (hue), \a s (saturation), \a l (lightness), and \a a
1963 (alpha-channel, i.e. transparency).
1965 The value of \a s, \a l, and \a a must all be in the range 0-255; the value
1966 of \a h must be in the range 0-359.
1968 \sa toHsl(), fromHslF(), isValid()
1970 QColor QColor::fromHsl(int h, int s, int l, int a)
1972 if (((h < 0 || h >= 360) && h != -1)
1975 || a < 0 || a > 255) {
1976 qWarning("QColor::fromHsv: HSV parameters out of range");
1982 color.ct.ahsl.alpha = a * 0x101;
1983 color.ct.ahsl.hue = h == -1 ? USHRT_MAX : (h % 360) * 100;
1984 color.ct.ahsl.saturation = s * 0x101;
1985 color.ct.ahsl.lightness = l * 0x101;
1986 color.ct.ahsl.pad = 0;
1994 Static convenience function that returns a QColor constructed from the HSV
1995 color values, \a h (hue), \a s (saturation), \a l (lightness), and \a a
1996 (alpha-channel, i.e. transparency).
1998 All the values must be in the range 0.0-1.0.
2000 \sa toHsl(), fromHsl(), isValid()
2002 QColor QColor::fromHslF(qreal h, qreal s, qreal l, qreal a)
2004 if (((h < qreal(0.0) || h > qreal(1.0)) && h != qreal(-1.0))
2005 || (s < qreal(0.0) || s > qreal(1.0))
2006 || (l < qreal(0.0) || l > qreal(1.0))
2007 || (a < qreal(0.0) || a > qreal(1.0))) {
2008 qWarning("QColor::fromHsvF: HSV parameters out of range");
2014 color.ct.ahsl.alpha = qRound(a * USHRT_MAX);
2015 color.ct.ahsl.hue = (h == qreal(-1.0)) ? USHRT_MAX : qRound(h * 36000);
2016 if (color.ct.ahsl.hue == 36000)
2017 color.ct.ahsl.hue = 0;
2018 color.ct.ahsl.saturation = qRound(s * USHRT_MAX);
2019 color.ct.ahsl.lightness = qRound(l * USHRT_MAX);
2020 color.ct.ahsl.pad = 0;
2026 Sets the contents pointed to by \a c, \a m, \a y, \a k, and \a a, to the
2027 cyan, magenta, yellow, black, and alpha-channel (transparency) components
2028 of the color's CMYK value.
2030 These components can be retrieved individually using the cyan(), magenta(),
2031 yellow(), black() and alpha() functions.
2033 \sa setCmyk(), {QColor#The CMYK Color Model}{The CMYK Color Model}
2035 void QColor::getCmyk(int *c, int *m, int *y, int *k, int *a)
2037 if (!c || !m || !y || !k)
2040 if (cspec != Invalid && cspec != Cmyk) {
2041 toCmyk().getCmyk(c, m, y, k, a);
2045 *c = ct.acmyk.cyan >> 8;
2046 *m = ct.acmyk.magenta >> 8;
2047 *y = ct.acmyk.yellow >> 8;
2048 *k = ct.acmyk.black >> 8;
2051 *a = ct.acmyk.alpha >> 8;
2055 Sets the contents pointed to by \a c, \a m, \a y, \a k, and \a a, to the
2056 cyan, magenta, yellow, black, and alpha-channel (transparency) components
2057 of the color's CMYK value.
2059 These components can be retrieved individually using the cyanF(),
2060 magentaF(), yellowF(), blackF() and alphaF() functions.
2062 \sa setCmykF(), {QColor#The CMYK Color Model}{The CMYK Color Model}
2064 void QColor::getCmykF(qreal *c, qreal *m, qreal *y, qreal *k, qreal *a)
2066 if (!c || !m || !y || !k)
2069 if (cspec != Invalid && cspec != Cmyk) {
2070 toCmyk().getCmykF(c, m, y, k, a);
2074 *c = ct.acmyk.cyan / qreal(USHRT_MAX);
2075 *m = ct.acmyk.magenta / qreal(USHRT_MAX);
2076 *y = ct.acmyk.yellow / qreal(USHRT_MAX);
2077 *k = ct.acmyk.black / qreal(USHRT_MAX);
2080 *a = ct.acmyk.alpha / qreal(USHRT_MAX);
2084 Sets the color to CMYK values, \a c (cyan), \a m (magenta), \a y (yellow),
2085 \a k (black), and \a a (alpha-channel, i.e. transparency).
2087 All the values must be in the range 0-255.
2089 \sa getCmyk(), setCmykF(), {QColor#The CMYK Color Model}{The CMYK Color Model}
2091 void QColor::setCmyk(int c, int m, int y, int k, int a)
2093 if (c < 0 || c > 255
2097 || a < 0 || a > 255) {
2098 qWarning("QColor::setCmyk: CMYK parameters out of range");
2103 ct.acmyk.alpha = a * 0x101;
2104 ct.acmyk.cyan = c * 0x101;
2105 ct.acmyk.magenta = m * 0x101;
2106 ct.acmyk.yellow = y * 0x101;
2107 ct.acmyk.black = k * 0x101;
2113 Sets the color to CMYK values, \a c (cyan), \a m (magenta), \a y (yellow),
2114 \a k (black), and \a a (alpha-channel, i.e. transparency).
2116 All the values must be in the range 0.0-1.0.
2118 \sa getCmykF(), setCmyk(), {QColor#The CMYK Color Model}{The CMYK Color Model}
2120 void QColor::setCmykF(qreal c, qreal m, qreal y, qreal k, qreal a)
2122 if (c < qreal(0.0) || c > qreal(1.0)
2123 || m < qreal(0.0) || m > qreal(1.0)
2124 || y < qreal(0.0) || y > qreal(1.0)
2125 || k < qreal(0.0) || k > qreal(1.0)
2126 || a < qreal(0.0) || a > qreal(1.0)) {
2127 qWarning("QColor::setCmykF: CMYK parameters out of range");
2132 ct.acmyk.alpha = qRound(a * USHRT_MAX);
2133 ct.acmyk.cyan = qRound(c * USHRT_MAX);
2134 ct.acmyk.magenta = qRound(m * USHRT_MAX);
2135 ct.acmyk.yellow = qRound(y * USHRT_MAX);
2136 ct.acmyk.black = qRound(k * USHRT_MAX);
2140 Static convenience function that returns a QColor constructed from the
2141 given CMYK color values: \a c (cyan), \a m (magenta), \a y (yellow), \a k
2142 (black), and \a a (alpha-channel, i.e. transparency).
2144 All the values must be in the range 0-255.
2146 \sa toCmyk(), fromCmykF(), isValid(), {QColor#The CMYK Color Model}{The CMYK Color Model}
2148 QColor QColor::fromCmyk(int c, int m, int y, int k, int a)
2150 if (c < 0 || c > 255
2154 || a < 0 || a > 255) {
2155 qWarning("QColor::fromCmyk: CMYK parameters out of range");
2161 color.ct.acmyk.alpha = a * 0x101;
2162 color.ct.acmyk.cyan = c * 0x101;
2163 color.ct.acmyk.magenta = m * 0x101;
2164 color.ct.acmyk.yellow = y * 0x101;
2165 color.ct.acmyk.black = k * 0x101;
2172 Static convenience function that returns a QColor constructed from the
2173 given CMYK color values: \a c (cyan), \a m (magenta), \a y (yellow), \a k
2174 (black), and \a a (alpha-channel, i.e. transparency).
2176 All the values must be in the range 0.0-1.0.
2178 \sa toCmyk(), fromCmyk(), isValid(), {QColor#The CMYK Color Model}{The CMYK Color Model}
2180 QColor QColor::fromCmykF(qreal c, qreal m, qreal y, qreal k, qreal a)
2182 if (c < qreal(0.0) || c > qreal(1.0)
2183 || m < qreal(0.0) || m > qreal(1.0)
2184 || y < qreal(0.0) || y > qreal(1.0)
2185 || k < qreal(0.0) || k > qreal(1.0)
2186 || a < qreal(0.0) || a > qreal(1.0)) {
2187 qWarning("QColor::fromCmykF: CMYK parameters out of range");
2193 color.ct.acmyk.alpha = qRound(a * USHRT_MAX);
2194 color.ct.acmyk.cyan = qRound(c * USHRT_MAX);
2195 color.ct.acmyk.magenta = qRound(m * USHRT_MAX);
2196 color.ct.acmyk.yellow = qRound(y * USHRT_MAX);
2197 color.ct.acmyk.black = qRound(k * USHRT_MAX);
2202 \fn QColor QColor::lighter(int factor) const
2205 Returns a lighter (or darker) color, but does not change this object.
2207 If the \a factor is greater than 100, this functions returns a lighter
2208 color. Setting \a factor to 150 returns a color that is 50% brighter. If
2209 the \a factor is less than 100, the return color is darker, but we
2210 recommend using the darker() function for this purpose. If the \a factor
2211 is 0 or negative, the return value is unspecified.
2213 The function converts the current RGB color to HSV, multiplies the value
2214 (V) component by \a factor and converts the color back to RGB.
2216 \sa darker(), isValid()
2222 Use lighter(\a factor) instead.
2224 QColor QColor::light(int factor) const
2226 if (factor <= 0) // invalid lightness factor
2228 else if (factor < 100) // makes color darker
2229 return darker(10000 / factor);
2231 QColor hsv = toHsv();
2232 int s = hsv.ct.ahsv.saturation;
2233 uint v = hsv.ct.ahsv.value;
2236 if (v > USHRT_MAX) {
2237 // overflow... adjust saturation
2244 hsv.ct.ahsv.saturation = s;
2245 hsv.ct.ahsv.value = v;
2247 // convert back to same color spec as original color
2248 return hsv.convertTo(cspec);
2252 \fn QColor QColor::darker(int factor) const
2255 Returns a darker (or lighter) color, but does not change this object.
2257 If the \a factor is greater than 100, this functions returns a darker
2258 color. Setting \a factor to 300 returns a color that has one-third the
2259 brightness. If the \a factor is less than 100, the return color is lighter,
2260 but we recommend using the lighter() function for this purpose. If the
2261 \a factor is 0 or negative, the return value is unspecified.
2263 The function converts the current RGB color to HSV, divides the value (V)
2264 component by \a factor and converts the color back to RGB.
2266 \sa lighter(), isValid()
2272 Use darker(\a factor) instead.
2274 QColor QColor::dark(int factor) const
2276 if (factor <= 0) // invalid darkness factor
2278 else if (factor < 100) // makes color lighter
2279 return lighter(10000 / factor);
2281 QColor hsv = toHsv();
2282 hsv.ct.ahsv.value = (hsv.ct.ahsv.value * 100) / factor;
2284 // convert back to same color spec as original color
2285 return hsv.convertTo(cspec);
2289 Assigns a copy of \a color to this color, and returns a reference to it.
2291 QColor &QColor::operator=(const QColor &color)
2293 cspec = color.cspec;
2294 ct.argb = color.ct.argb;
2299 Assigns a copy of \a color and returns a reference to this color.
2301 QColor &QColor::operator=(Qt::GlobalColor color)
2303 return operator=(QColor(color));
2307 Returns true if this color has the same RGB and alpha values as \a color;
2308 otherwise returns false.
2310 bool QColor::operator==(const QColor &color) const
2312 if (cspec == Hsl && cspec == color.cspec) {
2313 return (ct.argb.alpha == color.ct.argb.alpha
2314 && ((((ct.ahsl.hue % 36000) == (color.ct.ahsl.hue % 36000)))
2315 || (ct.ahsl.hue == color.ct.ahsl.hue))
2316 && (qAbs(ct.ahsl.saturation - color.ct.ahsl.saturation) < 50
2317 || ct.ahsl.lightness == 0
2318 || color.ct.ahsl.lightness == 0
2319 || ct.ahsl.lightness == USHRT_MAX
2320 || color.ct.ahsl.lightness == USHRT_MAX)
2321 && (qAbs(ct.ahsl.lightness - color.ct.ahsl.lightness)) < 50);
2323 return (cspec == color.cspec
2324 && ct.argb.alpha == color.ct.argb.alpha
2325 && (((cspec == QColor::Hsv)
2326 && ((ct.ahsv.hue % 36000) == (color.ct.ahsv.hue % 36000)))
2327 || (ct.ahsv.hue == color.ct.ahsv.hue))
2328 && ct.argb.green == color.ct.argb.green
2329 && ct.argb.blue == color.ct.argb.blue
2330 && ct.argb.pad == color.ct.argb.pad);
2335 Returns true if this color has a different RGB and alpha values from
2336 \a color; otherwise returns false.
2338 bool QColor::operator!=(const QColor &color) const
2339 { return !operator==(color); }
2343 Returns the color as a QVariant
2345 QColor::operator QVariant() const
2347 return QVariant(QVariant::Color, this);
2352 Marks the color as invalid and sets all components to zero (alpha is set
2353 to fully opaque for compatibility with Qt 3).
2355 void QColor::invalidate()
2358 ct.argb.alpha = USHRT_MAX;
2365 /*****************************************************************************
2366 QColor stream functions
2367 *****************************************************************************/
2369 #ifndef QT_NO_DEBUG_STREAM
2370 QDebug operator<<(QDebug dbg, const QColor &c)
2373 dbg.nospace() << "QColor(Invalid)";
2374 else if (c.spec() == QColor::Rgb)
2375 dbg.nospace() << "QColor(ARGB " << c.alphaF() << ", " << c.redF() << ", " << c.greenF() << ", " << c.blueF() << ')';
2376 else if (c.spec() == QColor::Hsv)
2377 dbg.nospace() << "QColor(AHSV " << c.alphaF() << ", " << c.hueF() << ", " << c.saturationF() << ", " << c.valueF() << ')';
2378 else if (c.spec() == QColor::Cmyk)
2379 dbg.nospace() << "QColor(ACMYK " << c.alphaF() << ", " << c.cyanF() << ", " << c.magentaF() << ", " << c.yellowF() << ", "
2380 << c.blackF()<< ')';
2381 else if (c.spec() == QColor::Hsl)
2382 dbg.nospace() << "QColor(AHSL " << c.alphaF() << ", " << c.hslHueF() << ", " << c.hslSaturationF() << ", " << c.lightnessF() << ')';
2388 #ifndef QT_NO_DATASTREAM
2390 \fn QDataStream &operator<<(QDataStream &stream, const QColor &color)
2393 Writes the \a color to the \a stream.
2395 \sa {Serializing Qt Data Types}
2397 QDataStream &operator<<(QDataStream &stream, const QColor &color)
2399 if (stream.version() < 7) {
2400 if (!color.isValid())
2401 return stream << quint32(0x49000000);
2402 quint32 p = (quint32)color.rgb();
2403 if (stream.version() == 1) // Swap red and blue
2404 p = ((p << 16) & 0xff0000) | ((p >> 16) & 0xff) | (p & 0xff00ff00);
2408 qint8 s = color.cspec;
2409 quint16 a = color.ct.argb.alpha;
2410 quint16 r = color.ct.argb.red;
2411 quint16 g = color.ct.argb.green;
2412 quint16 b = color.ct.argb.blue;
2413 quint16 p = color.ct.argb.pad;
2426 \fn QDataStream &operator>>(QDataStream &stream, QColor &color)
2429 Reads the \a color from the \a stream.
2431 \sa {Serializing Qt Data Types}
2433 QDataStream &operator>>(QDataStream &stream, QColor &color)
2435 if (stream.version() < 7) {
2438 if (p == 0x49000000) {
2442 if (stream.version() == 1) // Swap red and blue
2443 p = ((p << 16) & 0xff0000) | ((p >> 16) & 0xff) | (p & 0xff00ff00);
2449 quint16 a, r, g, b, p;
2457 color.cspec = QColor::Spec(s);
2458 color.ct.argb.alpha = a;
2459 color.ct.argb.red = r;
2460 color.ct.argb.green = g;
2461 color.ct.argb.blue = b;
2462 color.ct.argb.pad = p;
2466 #endif // QT_NO_DATASTREAM
2469 /*****************************************************************************
2470 QColor global functions (documentation only)
2471 *****************************************************************************/
2474 \fn int qRed(QRgb rgb)
2477 Returns the red component of the ARGB quadruplet \a rgb.
2479 \sa qRgb(), QColor::red()
2483 \fn int qGreen(QRgb rgb)
2486 Returns the green component of the ARGB quadruplet \a rgb.
2488 \sa qRgb(), QColor::green()
2492 \fn int qBlue(QRgb rgb)
2495 Returns the blue component of the ARGB quadruplet \a rgb.
2497 \sa qRgb(), QColor::blue()
2501 \fn int qAlpha(QRgb rgba)
2504 Returns the alpha component of the ARGB quadruplet \a rgba.
2506 \sa qRgb(), QColor::alpha()
2510 \fn QRgb qRgb(int r, int g, int b)
2513 Returns the ARGB quadruplet (255, \a{r}, \a{g}, \a{b}).
2515 \sa qRgba(), qRed(), qGreen(), qBlue()
2519 \fn QRgb qRgba(int r, int g, int b, int a)
2522 Returns the ARGB quadruplet (\a{a}, \a{r}, \a{g}, \a{b}).
2524 \sa qRgb(), qRed(), qGreen(), qBlue()
2528 \fn int qGray(int r, int g, int b)
2531 Returns a gray value (0 to 255) from the (\a r, \a g, \a b)
2534 The gray value is calculated using the formula (\a r * 11 + \a g * 16 +
2539 \fn int qGray(QRgb rgb)
2543 Returns a gray value (0 to 255) from the given ARGB quadruplet \a rgb.
2545 The gray value is calculated using the formula (R * 11 + G * 16 + B * 5)/32;
2546 the alpha-channel is ignored.
2550 \fn QColor QColor::convertTo(Spec colorSpec) const
2552 Creates a copy of \e this color in the format specified by \a colorSpec.
2554 \sa spec(), toCmyk(), toHsv(), toRgb(), isValid()
2561 An ARGB quadruplet on the format #AARRGGBB, equivalent to an unsigned int.
2563 The type also holds a value for the alpha-channel. The default alpha
2564 channel is \c ff, i.e opaque. For more information, see the
2565 \l{QColor#Alpha-Blended Drawing}{Alpha-Blended Drawing} section.
2567 \sa QColor::rgb(), QColor::rgba()