You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
qt3/doc/html/qcolor.html

619 lines
33 KiB

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/kernel/qcolor.cpp:45 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>QColor Class</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
<a href="index.html">
<font color="#004faf">Home</font></a>
| <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
| <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
| <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
| <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
| <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QColor Class Reference</h1>
<p>The QColor class provides colors based on RGB or HSV values.
<a href="#details">More...</a>
<p><tt>#include &lt;<a href="qcolor-h.html">qcolor.h</a>&gt;</tt>
<p><a href="qcolor-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li class=fn>enum <a href="#Spec-enum"><b>Spec</b></a> { Rgb, Hsv }</li>
<li class=fn><a href="#QColor"><b>QColor</b></a> ()</li>
<li class=fn><a href="#QColor-2"><b>QColor</b></a> ( int&nbsp;r, int&nbsp;g, int&nbsp;b )</li>
<li class=fn><a href="#QColor-3"><b>QColor</b></a> ( int&nbsp;x, int&nbsp;y, int&nbsp;z, Spec&nbsp;colorSpec )</li>
<li class=fn><a href="#QColor-4"><b>QColor</b></a> ( QRgb&nbsp;rgb, uint&nbsp;pixel = 0xffffffff )</li>
<li class=fn><a href="#QColor-5"><b>QColor</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;name )</li>
<li class=fn><a href="#QColor-6"><b>QColor</b></a> ( const&nbsp;char&nbsp;*&nbsp;name )</li>
<li class=fn><a href="#QColor-7"><b>QColor</b></a> ( const&nbsp;QColor&nbsp;&amp;&nbsp;c )</li>
<li class=fn>QColor &amp; <a href="#operator-eq"><b>operator=</b></a> ( const&nbsp;QColor&nbsp;&amp;&nbsp;c )</li>
<li class=fn>bool <a href="#isValid"><b>isValid</b></a> () const</li>
<li class=fn>QString <a href="#name"><b>name</b></a> () const</li>
<li class=fn>void <a href="#setNamedColor"><b>setNamedColor</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;name )</li>
<li class=fn>QRgb <a href="#rgb"><b>rgb</b></a> () const</li>
<li class=fn>void <a href="#setRgb"><b>setRgb</b></a> ( int&nbsp;r, int&nbsp;g, int&nbsp;b )</li>
<li class=fn>void <a href="#setRgb-2"><b>setRgb</b></a> ( QRgb&nbsp;rgb )</li>
<li class=fn>void <a href="#getRgb"><b>getRgb</b></a> ( int&nbsp;*&nbsp;r, int&nbsp;*&nbsp;g, int&nbsp;*&nbsp;b ) const</li>
<li class=fn>void rgb ( int&nbsp;*&nbsp;r, int&nbsp;*&nbsp;g, int&nbsp;*&nbsp;b ) const &nbsp;<em>(obsolete)</em></li>
<li class=fn>int <a href="#red"><b>red</b></a> () const</li>
<li class=fn>int <a href="#green"><b>green</b></a> () const</li>
<li class=fn>int <a href="#blue"><b>blue</b></a> () const</li>
<li class=fn>void <a href="#setHsv"><b>setHsv</b></a> ( int&nbsp;h, int&nbsp;s, int&nbsp;v )</li>
<li class=fn>void <a href="#getHsv"><b>getHsv</b></a> ( int&nbsp;*&nbsp;h, int&nbsp;*&nbsp;s, int&nbsp;*&nbsp;v ) const</li>
<li class=fn>void hsv ( int&nbsp;*&nbsp;h, int&nbsp;*&nbsp;s, int&nbsp;*&nbsp;v ) const &nbsp;<em>(obsolete)</em></li>
<li class=fn>void getHsv ( int&nbsp;&amp;&nbsp;h, int&nbsp;&amp;&nbsp;s, int&nbsp;&amp;&nbsp;v ) const &nbsp;<em>(obsolete)</em></li>
<li class=fn>QColor <a href="#light"><b>light</b></a> ( int&nbsp;factor = 150 ) const</li>
<li class=fn>QColor <a href="#dark"><b>dark</b></a> ( int&nbsp;factor = 200 ) const</li>
<li class=fn>bool <a href="#operator-eq-eq"><b>operator==</b></a> ( const&nbsp;QColor&nbsp;&amp;&nbsp;c ) const</li>
<li class=fn>bool <a href="#operator!-eq"><b>operator!=</b></a> ( const&nbsp;QColor&nbsp;&amp;&nbsp;c ) const</li>
<li class=fn>uint <a href="#alloc"><b>alloc</b></a> ()</li>
<li class=fn>uint <a href="#pixel"><b>pixel</b></a> () const</li>
<li class=fn>uint <a href="#pixel-2"><b>pixel</b></a> ( int&nbsp;screen ) const</li>
</ul>
<h2>Static Public Members</h2>
<ul>
<li class=fn>int <a href="#maxColors"><b>maxColors</b></a> ()</li>
<li class=fn>int <a href="#numBitPlanes"><b>numBitPlanes</b></a> ()</li>
<li class=fn>int <a href="#enterAllocContext"><b>enterAllocContext</b></a> ()</li>
<li class=fn>void <a href="#leaveAllocContext"><b>leaveAllocContext</b></a> ()</li>
<li class=fn>int <a href="#currentAllocContext"><b>currentAllocContext</b></a> ()</li>
<li class=fn>void <a href="#destroyAllocContext"><b>destroyAllocContext</b></a> ( int&nbsp;context )</li>
<li class=fn>void <a href="#initialize"><b>initialize</b></a> ()</li>
<li class=fn>void <a href="#cleanup"><b>cleanup</b></a> ()</li>
<li class=fn>QStringList <a href="#colorNames"><b>colorNames</b></a> ()</li>
</ul>
<h2>Related Functions</h2>
<ul>
<li class=fn>QDataStream &amp; <a href="#operator-lt-lt"><b>operator&lt;&lt;</b></a> ( QDataStream&nbsp;&amp;&nbsp;s, const&nbsp;QColor&nbsp;&amp;&nbsp;c )</li>
<li class=fn>QDataStream &amp; <a href="#operator-gt-gt"><b>operator&gt;&gt;</b></a> ( QDataStream&nbsp;&amp;&nbsp;s, QColor&nbsp;&amp;&nbsp;c )</li>
<li class=fn>int <a href="#qRed"><b>qRed</b></a> ( QRgb&nbsp;rgb )</li>
<li class=fn>int <a href="#qGreen"><b>qGreen</b></a> ( QRgb&nbsp;rgb )</li>
<li class=fn>int <a href="#qBlue"><b>qBlue</b></a> ( QRgb&nbsp;rgb )</li>
<li class=fn>int <a href="#qAlpha"><b>qAlpha</b></a> ( QRgb&nbsp;rgba )</li>
<li class=fn>QRgb <a href="#qRgb"><b>qRgb</b></a> ( int&nbsp;r, int&nbsp;g, int&nbsp;b )</li>
<li class=fn>QRgb <a href="#qRgba"><b>qRgba</b></a> ( int&nbsp;r, int&nbsp;g, int&nbsp;b, int&nbsp;a )</li>
<li class=fn>int <a href="#qGray"><b>qGray</b></a> ( int&nbsp;r, int&nbsp;g, int&nbsp;b )</li>
<li class=fn>int <a href="#qGray-2"><b>qGray</b></a> ( qRgb&nbsp;rgb )</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>
The QColor class provides colors based on RGB or HSV values.
<p>
<p> A color is normally specified in terms of RGB (red, green and blue)
components, but it is also possible to specify HSV (hue, saturation
and value) or set a color name (the names are copied from from the
X11 color database).
<p> In addition to the RGB value, a QColor also has a pixel value and a
validity. The pixel value is used by the underlying window system
to refer to a color. It can be thought of as an index into the
display hardware's color table.
<p> The validity (<a href="#isValid">isValid</a>()) indicates whether the color 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. The result of using an invalid color is unspecified and
will usually be surprising.
<p> There are 19 predefined QColor objects: <tt>white</tt>, <tt>black</tt>, <tt>red</tt>, <tt>darkRed</tt>, <tt>green</tt>, <tt>darkGreen</tt>, <tt>blue</tt>, <tt>darkBlue</tt>, <tt>cyan</tt>, <tt>darkCyan</tt>, <tt>magenta</tt>, <tt>darkMagenta</tt>, <tt>yellow</tt>, <tt>darkYellow</tt>, <tt>gray</tt>, <tt>darkGray</tt>, <tt>lightGray</tt>, <tt>color0</tt> and <tt>color1</tt>, accessible as members of the Qt namespace (ie. <tt>Qt::red</tt>).
<p> <center><img src="qt-colors.png" alt="Qt Colors"></center>
<p> The colors <tt>color0</tt> (zero pixel value) and <tt>color1</tt> (non-zero
pixel value) are special colors for drawing in <a href="qbitmap.html">bitmaps</a>. Painting with <tt>color0</tt> sets the bitmap bits to 0
(transparent, i.e. background), and painting with <tt>color1</tt> sets the
bits to 1 (opaque, i.e. foreground).
<p> The QColor class has an efficient, dynamic color allocation
strategy. A color is normally allocated the first time it is used
(lazy allocation), that is, whenever the <a href="#pixel">pixel</a>() function is called.
The following steps are taken to allocate a color. If, at any point,
a suitable color is found then the appropriate pixel value is
returned and the subsequent steps are not taken:
<p> <ol type=1>
<li> Is the pixel value valid? If it is, just return it; otherwise,
allocate a pixel value.
<li> Check an internal hash table to see if we allocated an equal RGB
value earlier. If we did, set the corresponding pixel value for the
color and return it.
<li> Try to allocate the RGB value. If we succeed, we get a pixel value
that we save in the internal table with the RGB value.
Return the pixel value.
<li> The color could not be allocated. Find the closest matching
color, save it in the internal table, and return it.
</ol>
<p> A color can be set by passing <a href="#setNamedColor">setNamedColor</a>() an RGB string like
"#112233", or a color name, e.g. "blue". The names are taken from
X11's rgb.txt database but can also be used under Windows. To get
a lighter or darker color use <a href="#light">light</a>() and <a href="#dark">dark</a>() respectively.
Colors can also be set using <a href="#setRgb">setRgb</a>() and <a href="#setHsv">setHsv</a>(). The color
components can be accessed in one go with <a href="#rgb">rgb</a>() and <a href="#hsv">hsv</a>(), or
individually with <a href="#red">red</a>(), <a href="#green">green</a>() and <a href="#blue">blue</a>().
<p> Use <a href="#maxColors">maxColors</a>() and <a href="#numBitPlanes">numBitPlanes</a>() to determine the maximum number
of colors and the number of bit planes supported by the underlying
window system,
<p> If you need to allocate many colors temporarily, for example in an
image viewer application, <a href="#enterAllocContext">enterAllocContext</a>(), <a href="#leaveAllocContext">leaveAllocContext</a>() and
<a href="#destroyAllocContext">destroyAllocContext</a>() will prove useful.
<p> <h3> HSV Colors
</h3>
<a name="1"></a><p> Because many people don't know the HSV color model very well, we'll
cover it briefly here.
<p> 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.
<p> HSV, like RGB, has three components:
<p> <ul>
<p> <li> H, for hue, is either 0-359 if the color is chromatic (not
gray), or meaningless if it is gray. It represents degrees on the
color wheel familiar to most people. Red is 0 (degrees), green is
120 and blue is 240.
<p> <li> S, for saturation, is 0-255, and the bigger it is, the
stronger the color is. Grayish colors have saturation near 0; very
strong colors have saturation near 255.
<p> <li> V, for value, is 0-255 and represents lightness or brightness
of the color. 0 is black; 255 is as far from black as possible.
<p> </ul>
<p> 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.
<p> Qt returns a hue value of -1 for achromatic colors. If you pass a
too-big hue value, Qt forces it into range. Hue 360 or 720 is
treated as 0; hue 540 is treated as 180.
<p> <p>See also <a href="qpalette.html">QPalette</a>, <a href="qcolorgroup.html">QColorGroup</a>, <a href="qapplication.html#setColorSpec">QApplication::setColorSpec</a>(), <a href="http://www.poynton.com/ColorFAQ.html">Color FAQ</a>, <a href="appearance.html">Widget Appearance and Style</a>, <a href="graphics.html">Graphics Classes</a>, and <a href="images.html">Image Processing Classes</a>.
<hr><h2>Member Type Documentation</h2>
<h3 class=fn><a name="Spec-enum"></a>QColor::Spec</h3>
<p> The type of color specified, either RGB or HSV, e.g. in the
<tt>QColor::QColor( x, y, z, colorSpec)</tt> constructor.
<ul>
<li><tt>QColor::Rgb</tt>
<li><tt>QColor::Hsv</tt>
</ul>
<hr><h2>Member Function Documentation</h2>
<h3 class=fn><a name="QColor"></a>QColor::QColor ()
</h3>
<p> 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.
<p> The alpha value of an invalid color is unspecified.
<p> <p>See also <a href="#isValid">isValid</a>().
<h3 class=fn><a name="QColor-2"></a>QColor::QColor ( int&nbsp;r, int&nbsp;g, int&nbsp;b )
</h3>
<p> Constructs a color with the RGB value <em>r</em>, <em>g</em>, <em>b</em>, in the
same way as <a href="#setRgb">setRgb</a>().
<p> The color is left invalid if any or the arguments are illegal.
<p> <p>See also <a href="#setRgb">setRgb</a>().
<h3 class=fn><a name="QColor-3"></a>QColor::QColor ( int&nbsp;x, int&nbsp;y, int&nbsp;z, <a href="qcolor.html#Spec-enum">Spec</a>&nbsp;colorSpec )
</h3>
Constructs a color with the RGB or HSV value <em>x</em>, <em>y</em>, <em>z</em>.
<p> The arguments are an RGB value if <em>colorSpec</em> is QColor::Rgb. <em>x</em> (red), <em>y</em> (green), and <em>z</em> (blue). All of them must be in the
range 0-255.
<p> The arguments are an HSV value if <em>colorSpec</em> is QColor::Hsv. <em>x</em> (hue) must be -1 for achromatic colors and 0-359 for chromatic
colors; <em>y</em> (saturation) and <em>z</em> (value) must both be in the
range 0-255.
<p> <p>See also <a href="#setRgb">setRgb</a>() and <a href="#setHsv">setHsv</a>().
<h3 class=fn><a name="QColor-4"></a>QColor::QColor ( QRgb&nbsp;rgb, uint&nbsp;pixel = 0xffffffff )
</h3>
Constructs a color with the RGB value <em>rgb</em> and a custom pixel
value <em>pixel</em>.
<p> If <em>pixel</em> == 0xffffffff (the default), then the color uses the
RGB value in a standard way. If <em>pixel</em> is something else, then
the pixel value is set directly to <em>pixel</em>, skipping the normal
allocation procedure.
<h3 class=fn><a name="QColor-5"></a>QColor::QColor ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;name )
</h3>
Constructs a named color in the same way as <a href="#setNamedColor">setNamedColor</a>() using
name <em>name</em>.
<p> The color is left invalid if <em>name</em> cannot be parsed.
<p> <p>See also <a href="#setNamedColor">setNamedColor</a>().
<h3 class=fn><a name="QColor-6"></a>QColor::QColor ( const&nbsp;char&nbsp;*&nbsp;name )
</h3>
Constructs a named color in the same way as <a href="#setNamedColor">setNamedColor</a>() using
name <em>name</em>.
<p> The color is left invalid if <em>name</em> cannot be parsed.
<p> <p>See also <a href="#setNamedColor">setNamedColor</a>().
<h3 class=fn><a name="QColor-7"></a>QColor::QColor ( const&nbsp;<a href="qcolor.html">QColor</a>&nbsp;&amp;&nbsp;c )
</h3>
Constructs a color that is a copy of <em>c</em>.
<h3 class=fn>uint <a name="alloc"></a>QColor::alloc ()
</h3>
Allocates the RGB color and returns the pixel value.
<p> Allocating a color means to obtain a pixel value from the RGB
specification. The pixel value is an index into the global color
table, but should be considered an arbitrary platform-dependent value.
<p> The <a href="#pixel">pixel</a>() function calls <a href="#alloc">alloc</a>() if necessary, so in general you
don't need to call this function.
<p> <p>See also <a href="#enterAllocContext">enterAllocContext</a>().
<h3 class=fn>int <a name="blue"></a>QColor::blue () const
</h3>
<p> Returns the B (blue) component of the RGB value.
<h3 class=fn>void <a name="cleanup"></a>QColor::cleanup ()<tt> [static]</tt>
</h3>
Internal clean up required for QColor.
This function is called from the <a href="qapplication.html">QApplication</a> destructor.
<p> <p>See also <a href="#initialize">initialize</a>().
<h3 class=fn><a href="qstringlist.html">QStringList</a> <a name="colorNames"></a>QColor::colorNames ()<tt> [static]</tt>
</h3>
Returns a <a href="qstringlist.html">QStringList</a> containing the color names Qt knows about.
<h3 class=fn>int <a name="currentAllocContext"></a>QColor::currentAllocContext ()<tt> [static]</tt>
</h3>
Returns the current color allocation context.
<p> The default context is 0.
<p> <p>See also <a href="#enterAllocContext">enterAllocContext</a>() and <a href="#leaveAllocContext">leaveAllocContext</a>().
<h3 class=fn><a href="qcolor.html">QColor</a> <a name="dark"></a>QColor::dark ( int&nbsp;factor = 200 ) const
</h3>
Returns a darker (or lighter) color, but does not change this
object.
<p> Returns a darker color if <em>factor</em> is greater than 100. Setting
<em>factor</em> to 300 returns a color that has one-third the
brightness.
<p> Returns a lighter color if <em>factor</em> is less than 100. We
recommend using lighter() for this purpose. If <em>factor</em> is 0 or
negative, the return value is unspecified.
<p> (This function converts the current RGB color to HSV, divides V by
<em>factor</em> and converts back to RGB.)
<p> <p>See also <a href="#light">light</a>().
<p>Examples: <a href="desktop-example.html#x1725">desktop/desktop.cpp</a> and <a href="themes-example.html#x192">themes/wood.cpp</a>.
<h3 class=fn>void <a name="destroyAllocContext"></a>QColor::destroyAllocContext ( int&nbsp;context )<tt> [static]</tt>
</h3>
Destroys a color allocation context, <em>context</em>.
<p> This function deallocates all colors that were allocated in the
specified <em>context</em>. If <em>context</em> == -1, it frees up all colors
that the application has allocated. If <em>context</em> == -2, it frees
up all colors that the application has allocated, except those in
the default context.
<p> The function does nothing for true color displays.
<p> <p>See also <a href="#enterAllocContext">enterAllocContext</a>() and <a href="#alloc">alloc</a>().
<p>Example: <a href="showimg-example.html#x1313">showimg/showimg.cpp</a>.
<h3 class=fn>int <a name="enterAllocContext"></a>QColor::enterAllocContext ()<tt> [static]</tt>
</h3>
Enters a color allocation context and returns a non-zero unique
identifier.
<p> Color allocation contexts are useful for programs that need to
allocate many colors and throw them away later, like image
viewers. The allocation context functions work for true color
displays as well as for colormap displays, except that
<a href="#destroyAllocContext">QColor::destroyAllocContext</a>() does nothing for true color.
<p> Example:
<pre>
<a href="qpixmap.html">QPixmap</a> loadPixmap( <a href="qstring.html">QString</a> fileName )
{
static int alloc_context = 0;
if ( alloc_context )
QColor::<a href="#destroyAllocContext">destroyAllocContext</a>( alloc_context );
alloc_context = QColor::<a href="#enterAllocContext">enterAllocContext</a>();
<a href="qpixmap.html">QPixmap</a> pm( fileName );
QColor::<a href="#leaveAllocContext">leaveAllocContext</a>();
return pm;
}
</pre>
<p> The example code loads a pixmap from file. It frees up all colors
that were allocated the last time loadPixmap() was called.
<p> The initial/default context is 0. Qt keeps a list of colors
associated with their allocation contexts. You can call
<a href="#destroyAllocContext">destroyAllocContext</a>() to get rid of all colors that were allocated
in a specific context.
<p> Calling <a href="#enterAllocContext">enterAllocContext</a>() enters an allocation context. The
allocation context lasts until you call <a href="#leaveAllocContext">leaveAllocContext</a>().
QColor has an internal stack of allocation contexts. Each call to
enterAllocContex() must have a corresponding leaveAllocContext().
<p> <pre>
// context 0 active
int c1 = QColor::<a href="#enterAllocContext">enterAllocContext</a>(); // enter context c1
// context c1 active
int c2 = QColor::<a href="#enterAllocContext">enterAllocContext</a>(); // enter context c2
// context c2 active
QColor::<a href="#leaveAllocContext">leaveAllocContext</a>(); // leave context c2
// context c1 active
QColor::<a href="#leaveAllocContext">leaveAllocContext</a>(); // leave context c1
// context 0 active
// Now, free all colors that were allocated in context c2
QColor::<a href="#destroyAllocContext">destroyAllocContext</a>( c2 );
</pre>
<p> You may also want to set the application's color specification.
See <a href="qapplication.html#setColorSpec">QApplication::setColorSpec</a>() for more information.
<p> <p>See also <a href="#leaveAllocContext">leaveAllocContext</a>(), <a href="#currentAllocContext">currentAllocContext</a>(), <a href="#destroyAllocContext">destroyAllocContext</a>(), and <a href="qapplication.html#setColorSpec">QApplication::setColorSpec</a>().
<p>Example: <a href="showimg-example.html#x1314">showimg/showimg.cpp</a>.
<h3 class=fn>void <a name="getHsv"></a>QColor::getHsv ( int&nbsp;*&nbsp;h, int&nbsp;*&nbsp;s, int&nbsp;*&nbsp;v ) const
</h3>
<p> Returns the current RGB value as HSV. The contents of the <em>h</em>, <em>s</em> and <em>v</em> pointers are set to the HSV values. If any of the three
pointers are null, the function does nothing.
<p> The hue (which <em>h</em> points to) is set to -1 if the color is
achromatic.
<p> <b>Warning:</b> Colors are stored internally as RGB values, so getHSv()
may return slightly different values to those set by <a href="#setHsv">setHsv</a>().
<p> <p>See also <a href="#setHsv">setHsv</a>() and <a href="#rgb">rgb</a>().
<h3 class=fn>void <a name="getHsv-2"></a>QColor::getHsv ( int&nbsp;&amp;&nbsp;h, int&nbsp;&amp;&nbsp;s, int&nbsp;&amp;&nbsp;v ) const
</h3>
<b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code.
<p>
<h3 class=fn>void <a name="getRgb"></a>QColor::getRgb ( int&nbsp;*&nbsp;r, int&nbsp;*&nbsp;g, int&nbsp;*&nbsp;b ) const
</h3>
<p> Sets the contents pointed to by <em>r</em>, <em>g</em> and <em>b</em> to the red,
green and blue components of the RGB value respectively. The value
range for a component is 0..255.
<p> <p>See also <a href="#rgb">rgb</a>(), <a href="#setRgb">setRgb</a>(), and <a href="#getHsv">getHsv</a>().
<h3 class=fn>int <a name="green"></a>QColor::green () const
</h3>
<p> Returns the G (green) component of the RGB value.
<h3 class=fn>void <a name="hsv"></a>QColor::hsv ( int&nbsp;*&nbsp;h, int&nbsp;*&nbsp;s, int&nbsp;*&nbsp;v ) const
</h3> <b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code.
Use <a href="#getHsv">getHsv</a>() instead.
<p>Example: <a href="themes-example.html#x272">themes/metal.cpp</a>.
<h3 class=fn>void <a name="initialize"></a>QColor::initialize ()<tt> [static]</tt>
</h3>
Internal initialization required for QColor.
This function is called from the <a href="qapplication.html">QApplication</a> constructor.
<p> <p>See also <a href="#cleanup">cleanup</a>().
<h3 class=fn>bool <a name="isValid"></a>QColor::isValid () const
</h3>
<p> Returns FALSE if the color is invalid, i.e. it was constructed using the
default constructor; otherwise returns TRUE.
<p>Examples: <a href="tutorial2-03.html#x2550">chart/element.cpp</a>, <a href="tutorial2-08.html#x2599">chart/setdataform.cpp</a>, and <a href="scribble-example.html#x908">scribble/scribble.cpp</a>.
<h3 class=fn>void <a name="leaveAllocContext"></a>QColor::leaveAllocContext ()<tt> [static]</tt>
</h3>
Leaves a color allocation context.
<p> See <a href="#enterAllocContext">enterAllocContext</a>() for a detailed explanation.
<p> <p>See also <a href="#enterAllocContext">enterAllocContext</a>() and <a href="#currentAllocContext">currentAllocContext</a>().
<p>Example: <a href="showimg-example.html#x1315">showimg/showimg.cpp</a>.
<h3 class=fn><a href="qcolor.html">QColor</a> <a name="light"></a>QColor::light ( int&nbsp;factor = 150 ) const
</h3>
Returns a lighter (or darker) color, but does not change this
object.
<p> Returns a lighter color if <em>factor</em> is greater than 100. Setting
<em>factor</em> to 150 returns a color that is 50% brighter.
<p> Returns a darker color if <em>factor</em> is less than 100. We recommend
using <a href="#dark">dark</a>() for this purpose. If <em>factor</em> is 0 or negative, the
return value is unspecified.
<p> (This function converts the current RGB color to HSV, multiplies V
by <em>factor</em>, and converts the result back to RGB.)
<p> <p>See also <a href="#dark">dark</a>().
<p>Examples: <a href="desktop-example.html#x1726">desktop/desktop.cpp</a> and <a href="themes-example.html#x193">themes/wood.cpp</a>.
<h3 class=fn>int <a name="maxColors"></a>QColor::maxColors ()<tt> [static]</tt>
</h3>
Returns the maximum number of colors supported by the underlying
window system if the window system uses a palette.
<p> Otherwise returns -1. Use <a href="#numBitPlanes">numBitPlanes</a>() to calculate the available
colors in that case.
<h3 class=fn><a href="qstring.html">QString</a> <a name="name"></a>QColor::name () const
</h3>
Returns the name of the color in the format "#RRGGBB", i.e. a "#"
character followed by three two-digit hexadecimal numbers.
<p> <p>See also <a href="#setNamedColor">setNamedColor</a>().
<p>Example: <a href="tutorial2-08.html#x2600">chart/setdataform.cpp</a>.
<h3 class=fn>int <a name="numBitPlanes"></a>QColor::numBitPlanes ()<tt> [static]</tt>
</h3>
Returns the number of color bit planes for the underlying window
system.
<p> The returned value is equal to the default pixmap depth.
<p> <p>See also <a href="qpixmap.html#defaultDepth">QPixmap::defaultDepth</a>().
<h3 class=fn>bool <a name="operator!-eq"></a>QColor::operator!= ( const&nbsp;<a href="qcolor.html">QColor</a>&nbsp;&amp;&nbsp;c ) const
</h3>
Returns TRUE if this color has a different RGB value from <em>c</em>;
otherwise returns FALSE.
<h3 class=fn><a href="qcolor.html">QColor</a>&nbsp;&amp; <a name="operator-eq"></a>QColor::operator= ( const&nbsp;<a href="qcolor.html">QColor</a>&nbsp;&amp;&nbsp;c )
</h3>
Assigns a copy of the color <em>c</em> and returns a reference to this
color.
<h3 class=fn>bool <a name="operator-eq-eq"></a>QColor::operator== ( const&nbsp;<a href="qcolor.html">QColor</a>&nbsp;&amp;&nbsp;c ) const
</h3>
<p> Returns TRUE if this color has the same RGB value as <em>c</em>;
otherwise returns FALSE.
<h3 class=fn>uint <a name="pixel"></a>QColor::pixel () const
</h3>
Returns the pixel value.
<p> This value is used by the underlying window system to refer to a
color. It can be thought of as an index into the display
hardware's color table, but the value is an arbitrary 32-bit
value.
<p> <p>See also <a href="#alloc">alloc</a>().
<h3 class=fn>uint <a name="pixel-2"></a>QColor::pixel ( int&nbsp;screen ) const
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Returns the pixel value for screen <em>screen</em>.
<p> This value is used by the underlying window system to refer to a color.
It can be thought of as an index into the display hardware's color table,
but the value is an arbitrary 32-bit value.
<p> <p>See also <a href="#alloc">alloc</a>().
<h3 class=fn>int <a name="red"></a>QColor::red () const
</h3>
<p> Returns the R (red) component of the RGB value.
<h3 class=fn>QRgb <a name="rgb"></a>QColor::rgb () const
</h3>
<p> Returns the RGB value.
<p> The return type <em>QRgb</em> is equivalent to <tt>unsigned</tt> <tt>int</tt>.
<p> For an invalid color, the alpha value of the returned color is
unspecified.
<p> <p>See also <a href="#setRgb">setRgb</a>(), <a href="#hsv">hsv</a>(), <a href="#qRed">qRed</a>(), <a href="#qBlue">qBlue</a>(), <a href="#qGreen">qGreen</a>(), and <a href="#isValid">isValid</a>().
<h3 class=fn>void <a name="rgb-2"></a>QColor::rgb ( int&nbsp;*&nbsp;r, int&nbsp;*&nbsp;g, int&nbsp;*&nbsp;b ) const
</h3> <b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code.
Use <a href="#getRgb">getRgb</a>() instead
<h3 class=fn>void <a name="setHsv"></a>QColor::setHsv ( int&nbsp;h, int&nbsp;s, int&nbsp;v )
</h3>
Sets a HSV color value. <em>h</em> is the hue, <em>s</em> is the saturation
and <em>v</em> is the value of the HSV color.
<p> If <em>s</em> or <em>v</em> are not in the range 0-255, or <em>h</em> is < -1, the
color is not changed.
<p> <b>Warning:</b> Colors are stored internally as RGB values, so getHSv()
may return slightly different values to those set by <a href="#setHsv">setHsv</a>().
<p> <p>See also <a href="#hsv">hsv</a>() and <a href="#setRgb">setRgb</a>().
<p>Examples: <a href="drawdemo-example.html#x1063">drawdemo/drawdemo.cpp</a>, <a href="grapher-nsplugin-example.html#x2740">grapher/grapher.cpp</a>, and <a href="progress-example.html#x66">progress/progress.cpp</a>.
<h3 class=fn>void <a name="setNamedColor"></a>QColor::setNamedColor ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;name )
</h3>
Sets the RGB value to <em>name</em>, which may be in one of these
formats:
<ul>
<li> #RGB (each of R, G and B is a single hex digit)
<li> #RRGGBB
<li> #RRRGGGBBB
<li> #RRRRGGGGBBBB
<li> A name from the X color database (rgb.txt) (e.g.
"steelblue" or "gainsboro"). These color names also work
under Windows.
</ul>
<p> The color is invalid if <em>name</em> cannot be parsed.
<h3 class=fn>void <a name="setRgb"></a>QColor::setRgb ( int&nbsp;r, int&nbsp;g, int&nbsp;b )
</h3>
Sets the RGB value to <em>r</em>, <em>g</em>, <em>b</em>. The arguments, <em>r</em>, <em>g</em>
and <em>b</em> must all be in the range 0..255. If any of them are
outside the legal range, the color is not changed.
<p> <p>See also <a href="#rgb">rgb</a>() and <a href="#setHsv">setHsv</a>().
<h3 class=fn>void <a name="setRgb-2"></a>QColor::setRgb ( QRgb&nbsp;rgb )
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Sets the RGB value to <em>rgb</em>.
<p> The type <em>QRgb</em> is equivalent to <tt>unsigned</tt> <tt>int</tt>.
<p> <p>See also <a href="#rgb">rgb</a>() and <a href="#setHsv">setHsv</a>().
<hr><h2>Related Functions</h2>
<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-lt-lt"></a>operator&lt;&lt; ( <a href="qdatastream.html">QDataStream</a>&nbsp;&amp;&nbsp;s, const&nbsp;<a href="qcolor.html">QColor</a>&nbsp;&amp;&nbsp;c )
</h3>
Writes a color object, <em>c</em> to the stream, <em>s</em>.
<p> <p>See also <a href="datastreamformat.html">Format of the QDataStream operators</a>.
<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-gt-gt"></a>operator&gt;&gt; ( <a href="qdatastream.html">QDataStream</a>&nbsp;&amp;&nbsp;s, <a href="qcolor.html">QColor</a>&nbsp;&amp;&nbsp;c )
</h3>
Reads a color object, <em>c</em>, from the stream, <em>s</em>.
<p> <p>See also <a href="datastreamformat.html">Format of the QDataStream operators</a>.
<h3 class=fn>int <a name="qAlpha"></a>qAlpha ( QRgb&nbsp;rgba )
</h3>
<p> Returns the alpha component of the RGBA quadruplet <em>rgba</em>.
<h3 class=fn>int <a name="qBlue"></a>qBlue ( QRgb&nbsp;rgb )
</h3>
<p> Returns the blue component of the RGB triplet <em>rgb</em>.
<p>See also <a href="#qRgb">qRgb</a>() and <a href="#blue">QColor::blue</a>().
<h3 class=fn>int <a name="qGray"></a>qGray ( int&nbsp;r, int&nbsp;g, int&nbsp;b )
</h3>
<p> Returns a gray value 0..255 from the (<em>r</em>, <em>g</em>, <em>b</em>) triplet.
<p> The gray value is calculated using the formula (r*11 + g*16 +
b*5)/32.
<h3 class=fn>int <a name="qGray-2"></a>qGray ( qRgb&nbsp;rgb )
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p>
<p> Returns a gray value 0..255 from the given <em>rgb</em> colour.
<h3 class=fn>int <a name="qGreen"></a>qGreen ( QRgb&nbsp;rgb )
</h3>
<p> Returns the green component of the RGB triplet <em>rgb</em>.
<p>See also <a href="#qRgb">qRgb</a>() and <a href="#green">QColor::green</a>().
<h3 class=fn>int <a name="qRed"></a>qRed ( QRgb&nbsp;rgb )
</h3>
<p> Returns the red component of the RGB triplet <em>rgb</em>.
<p>See also <a href="#qRgb">qRgb</a>() and <a href="#red">QColor::red</a>().
<h3 class=fn>QRgb <a name="qRgb"></a>qRgb ( int&nbsp;r, int&nbsp;g, int&nbsp;b )
</h3>
<p> Returns the RGB triplet <em>(r,g,b)</em>.
<p> The return type QRgb is equivalent to <tt>unsigned</tt> <tt>int</tt>.
<p> <p>See also <a href="#qRgba">qRgba</a>(), <a href="#qRed">qRed</a>(), <a href="#qGreen">qGreen</a>(), and <a href="#qBlue">qBlue</a>().
<h3 class=fn>QRgb <a name="qRgba"></a>qRgba ( int&nbsp;r, int&nbsp;g, int&nbsp;b, int&nbsp;a )
</h3>
<p> Returns the RGBA quadruplet <em>(r,g,b,a)</em>.
<p> The return type QRgba is equivalent to <tt>unsigned</tt> <tt>int</tt>.
<p> <p>See also <a href="#qRgb">qRgb</a>(), <a href="#qRed">qRed</a>(), <a href="#qGreen">qGreen</a>(), and <a href="#qBlue">qBlue</a>().
<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>.
Copyright &copy; 1995-2007
<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt 3.3.8</div>
</table></div></address></body>
</html>