Overview | Package | Class | Tree | Deprecated | Index | Help
Qt Jambi Home |
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.trolltech.qt.gui
Class QColor

    java.lang.Object
      com.trolltech.qt.QSignalEmitter
          com.trolltech.qt.QtJambiObject
              com.trolltech.qt.gui.QColor

All Implemented Interfaces:
  QtJambiInterface

    public class QColor

extends QtJambiObject

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

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

RGB | HSV | CMYK
--- | --- | ---

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

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

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

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

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

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

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

- Integer vs. Floating Point Precision
- Alpha-Blended Drawing
- Predefined Colors
- The HSV Color Model
- The CMYK Color Model

### Integer vs. Floating Point Precision

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

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

### Alpha-Blended Drawing

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

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

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

The code above produces the following output:

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

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

### Predefined Colors

There are 20 predefined QColors: Qt::white, Qt::black, Qt::red, Qt::darkRed, Qt::green, Qt::darkGreen, Qt::blue, Qt::darkBlue, Qt::cyan, Qt::darkCyan, Qt::magenta, Qt::darkMagenta, Qt::yellow, Qt::darkYellow, Qt::gray, Qt::darkGray, Qt::lightGray, Qt::color0, Qt::color1, and Qt::transparent.

`QColor` provides the static `colorNames` function which returns a `QStringList` containing the color names Qt knows about.

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

### The HSV Color Model

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

HSV, like RGB, has three components:

- H, for hue, is in the range 0 to 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.

- S, for saturation, is in the range 0 to 255, and the bigger it is, the stronger the color is. Grayish colors have saturation near 0; very strong colors have saturation near 255.

- V, for value, is in the range 0 to 255 and represents lightness or brightness of the color. 0 is black; 255 is as far from black as possible.

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

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

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

### The CMYK Color Model

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

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

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

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

See Also:
  `QPalette`, `QBrush`, `QApplication::setColorSpec`

Nested Class Summary
`static class` | `QColor.Spec` The type of color specified, either RGB, HSV or CMYK.

Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
`QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>`

Field Summary
`static QColor` | `black`
`static QColor` | `blue`
`static QColor` | `color0`
`static QColor` | `color1`
`static QColor` | `cyan`
`static QColor` | `darkBlue`
`static QColor` | `darkCyan`
`static QColor` | `darkGray`
`static QColor` | `darkGreen`
`static QColor` | `darkMagenta`
`static QColor` | `darkRed`
`static QColor` | `darkYellow`
`static QColor` | `gray`
`static QColor` | `green`
`static QColor` | `lightGray`
`static QColor` | `magenta`
`static QColor` | `red`
`static QColor` | `transparent`
`static QColor` | `white`
`static QColor` | `yellow`

Constructor Summary
`QColor()` Constructs an invalid color with the RGB value (0, 0, 0).
`QColor(int rgb)` Constructs a color with the value `rgb`.
`QColor(int r, int g, int b)` Equivalent to `QColor`(`r`, `g`, `b`, 255).
`QColor(int r, int g, int b, int a)` Constructs a color with the RGB value `r`, `g`, `b`, and the alpha-channel (transparency) value of `a`.
`QColor(QColor color)` Constructs a color that is a copy of `color`.
`QColor(Qt.GlobalColor color)` Constructs a new color with a color value of `color`.
`QColor(java.lang.String name)` Constructs a named color in the same way as `setNamedColor` using the given `name`.

Method Summary
`int` | `alpha()` Returns the alpha color component of this color.
`double` | `alphaF()` Returns the alpha color component of this color.
`int` | `black()` Returns the black color component of this color.
`double` | `blackF()` Returns the black color component of this color.
`int` | `blue()` Returns the blue color component of this color.
`double` | `blueF()` Returns the blue color component of this color.
`static java.util.List<java.lang.String>` | `colorNames()` Returns a `QStringList` containing the color names Qt knows about.
`QColor` | `convertTo(QColor.Spec colorSpec)` Creates a copy of this color in the format specified by `colorSpec`.
`int` | `cyan()` Returns the cyan color component of this color.
`double` | `cyanF()` Returns the cyan color component of this color.
`QColor` | `darker()` Equivalent to darker(200).
`QColor` | `darker(int f)` Returns a darker (or lighter) color, but does not change this object.
`boolean` | `equals(java.lang.Object other)`
`static QColor` | `fromCmyk(int c, int m, int y, int k)` Equivalent to `fromCmyk`(`c`, `m`, `y`, `k`, 255).
`static QColor` | `fromCmyk(int c, int m, int y, int k, int a)` Static convenience function that returns a `QColor` constructed from the given CMYK color values: `c` (cyan), `m` (magenta), `y` (yellow), `k` (black), and `a` (alpha-channel, i.e. transparency).
`static QColor` | `fromCmykF(double c, double m, double y, double k)` Equivalent to `fromCmykF`(`c`, `m`, `y`, `k`, 1.0).
`static QColor` | `fromCmykF(double c, double m, double y, double k, double a)` Static convenience function that returns a `QColor` constructed from the given CMYK color values: `c` (cyan), `m` (magenta), `y` (yellow), `k` (black), and `a` (alpha-channel, i.e. transparency).
`static QColor` | `fromHsv(int h, int s, int v)` Equivalent to `fromHsv`(`h`, `s`, `v`, 255).
`static QColor` | `fromHsv(int h, int s, int v, int a)` Static convenience function that returns a `QColor` constructed from the HSV color values, `h` (hue), `s` (saturation), `v` (value), and `a` (alpha-channel, i.e. transparency).
`static QColor` | `fromHsvF(double h, double s, double v)` Equivalent to `fromHsvF`(`h`, `s`, `v`, 1.0).
`static QColor` | `fromHsvF(double h, double s, double v, double a)` Static convenience function that returns a `QColor` constructed from the HSV color values, `h` (hue), `s` (saturation), `v` (value), and `a` (alpha-channel, i.e. transparency).
`static QColor` | `fromNativePointer(QNativePointer nativePointer)` This function returns the QColor instance pointed to by nativePointer
`static QColor` | `fromRgb(int rgb)` Static convenience function that returns a `QColor` constructed from the given QRgb value `rgb`.
`static QColor` | `fromRgb(int r, int g, int b)` Equivalent to `fromRgb`(`r`, `g`, `b`, 255).
`static QColor` | `fromRgb(int r, int g, int b, int a)` Static convenience function that returns a `QColor` constructed from the RGB color values, `r` (red), `g` (green), `b` (blue), and `a` (alpha-channel, i.e. transparency).
`static QColor` | `fromRgba(int rgba)` Static convenience function that returns a `QColor` constructed from the given QRgb value `rgba`.
`static QColor` | `fromRgbF(double r, double g, double b)` Equivalent to `fromRgbF`(`r`, `g`, `b`, 1.0).
`static QColor` | `fromRgbF(double r, double g, double b, double a)` Static convenience function that returns a `QColor` constructed from the RGB color values, `r` (red), `g` (green), `b` (blue), and `a` (alpha-channel, i.e. transparency).
`int` | `green()` Returns the green color component of this color.
`double` | `greenF()` Returns the green color component of this color.
`int` | `hue()` Returns the hue color component of this color.
`double` | `hueF()` Returns the hue color component of this color.
`boolean` | `isValid()` Returns true if the color is valid; otherwise returns false.
`QColor` | `lighter()` Equivalent to lighter(150).
`QColor` | `lighter(int f)` Returns a lighter (or darker) color, but does not change this object.
`int` | `magenta()` Returns the magenta color component of this color.
`double` | `magentaF()` Returns the magenta color component of this color.
`java.lang.String` | `name()` Returns the name of the color in the format "#RRGGBB"; i.e. a "#" character followed by three two-digit hexadecimal numbers.
`static QNativePointer` | `nativePointerArray(QColor[] array)` This function returns a QNativePointer that is pointing to the specified QColor array.
`void` | `readFrom(QDataStream arg__1)` Reads a QColor from arg__1.
`int` | `red()` Returns the red color component of this color.
`double` | `redF()` Returns the red color component of this color.
`int` | `rgb()` Returns the RGB value of the color.
`int` | `rgba()` Returns the RGB value of the color.
`int` | `saturation()` Returns the saturation color component of this color.
`double` | `saturationF()` Returns the saturation color component of this color.
`void` | `setAlpha(int alpha)` Sets the alpha of this color to `alpha`.
`void` | `setAlphaF(double alpha)` Sets the alpha of this color to `alpha`.
`void` | `setBlue(int blue)` Sets the blue color component of this color to `blue`.
`void` | `setBlueF(double blue)` Sets the blue color component of this color to `blue`.
`void` | `setCmyk(int c, int m, int y, int k)` Equivalent to `setCmyk`(`c`, `m`, `y`, `k`, 255).
`void` | `setCmyk(int c, int m, int y, int k, int a)` Sets the color to CMYK values, `c` (cyan), `m` (magenta), `y` (yellow), `k` (black), and `a` (alpha-channel, i.e. transparency).
`void` | `setCmykF(double c, double m, double y, double k)` Equivalent to `setCmykF`(`c`, `m`, `y`, `k`, 1.0).
`void` | `setCmykF(double c, double m, double y, double k, double a)` Sets the color to CMYK values, `c` (cyan), `m` (magenta), `y` (yellow), `k` (black), and `a` (alpha-channel, i.e. transparency).
`void` | `setGreen(int green)` Sets the green color component of this color to `green`.
`void` | `setGreenF(double green)` Sets the green color component of this color to `green`.
`void` | `setHsv(int h, int s, int v)` Equivalent to `setHsv`(`h`, `s`, `v`, 255).
`void` | `setHsv(int h, int s, int v, int a)` Sets a HSV color value; `h` is the hue, `s` is the saturation, `v` is the value and `a` is the alpha component of the HSV color.
`void` | `setHsvF(double h, double s, double v)` Equivalent to `setHsvF`(`h`, `s`, `v`, 1.0).
`void` | `setHsvF(double h, double s, double v, double a)` Sets a HSV color value; `h` is the hue, `s` is the saturation, `v` is the value and `a` is the alpha component of the HSV color.
`void` | `setNamedColor(java.lang.String name)` Sets the RGB value of this `QColor` to `name`, which may be in one of these formats:
`void` | `setRed(int red)` Sets the red color component of this color to `red`.
`void` | `setRedF(double red)` Sets the red color component of this color to `red`.
`void` | `setRgb(int rgb)` Sets the RGB value to `rgb`, ignoring the alpha.
`void` | `setRgb(int r, int g, int b)` Equivalent to `setRgb`(`r`, `g`, `b`, 255).
`void` | `setRgb(int r, int g, int b, int a)` Sets the RGB value to `r`, `g`, `b` and the alpha value to `a`.
`void` | `setRgba(int rgba)` Sets the RGBA value to `rgba`.
`void` | `setRgbF(double r, double g, double b)` Equivalent to `setRgbF`(`r`, `g`, `b`, 1.0).
`void` | `setRgbF(double r, double g, double b, double a)` Sets the color channels of this color to `r` (red), `g` (green), `b` (blue) and `a` (alpha, transparency).
`QColor.Spec` | `spec()` Returns how the color was specified.
`QColor` | `toCmyk()` Creates and returns a CMYK `QColor` based on this color.
`QColor` | `toHsv()` Creates and returns an HSV `QColor` based on this color.
`QColor` | `toRgb()` Create and returns an RGB `QColor` based on this color.
`java.lang.String` | `toString()` Returns a string representation of this QColor.
`int` | `value()` Returns the value color component of this color.
`double` | `valueF()` Returns the value color component of this color.
`void` | `writeTo(QDataStream arg__1)` Writes thisQColor to arg__1.
`int` | `yellow()` Returns the yellow color component of this color.
`double` | `yellowF()` Returns the yellow color component of this color.

Methods inherited from class com.trolltech.qt.QtJambiObject
`dispose, disposed, finalize, reassignNativeResources, tr, tr, tr`

Methods inherited from class com.trolltech.qt.QSignalEmitter
`blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread`

Methods inherited from class java.lang.Object
`clone, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface com.trolltech.qt.QtJambiInterface
`disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership`

Field Detail

### white

    public static final QColor white

### black

    public static final QColor black

### red

    public static final QColor red

### darkRed

    public static final QColor darkRed

### green

    public static final QColor green

### darkGreen

    public static final QColor darkGreen

### blue

    public static final QColor blue

### darkBlue

    public static final QColor darkBlue

### cyan

    public static final QColor cyan

### darkCyan

    public static final QColor darkCyan

### magenta

    public static final QColor magenta

### darkMagenta

    public static final QColor darkMagenta

### yellow

    public static final QColor yellow

### darkYellow

    public static final QColor darkYellow

### gray

    public static final QColor gray

### darkGray

    public static final QColor darkGray

### lightGray

    public static final QColor lightGray

### transparent

    public static final QColor transparent

### color0

    public static final QColor color0

### color1

    public static final QColor color1

Constructor Detail

### QColor

    public QColor(int rgb)

  Constructs a color with the value `rgb`. The alpha component is ignored and set to solid.

  See Also:
    `fromRgb`, `isValid`

### QColor

    public QColor(Qt.GlobalColor color)

  Constructs a new color with a color value of `color`.

  See Also:
    `isValid`, `Colors`

### QColor

    public QColor(int r,
                  int g,
                  int b)

  Equivalent to `QColor`(`r`, `g`, `b`, 255).

### QColor

    public QColor(int r,
                  int g,
                  int b,
                  int a)

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

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

  See Also:
    `setRgba`, `isValid`

### QColor

    public QColor(QColor color)

  Constructs a color that is a copy of `color`.

  See Also:
    `isValid`

### QColor

    public QColor()

  Constructs an invalid color with the RGB value (0, 0, 0). An invalid color is a color that is not properly set up for the underlying window system.

  The alpha value of an invalid color is unspecified.

  See Also:
    `isValid`

### QColor

    public QColor(java.lang.String name)

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

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

  See Also:
    `setNamedColor`, `name`, `isValid`

Method Detail

### alpha

    public final int alpha()

  Returns the alpha color component of this color.

  See Also:
    `setAlpha`, `alphaF`, `Drawing`

### alphaF

    public final double alphaF()

  Returns the alpha color component of this color.

  See Also:
    `setAlphaF`, `alpha`, `Drawing`

### black

    public final int black()

  Returns the black color component of this color.

  See Also:
    `blackF`, `getCmyk`, `CMYK Color Model`

### blackF

    public final double blackF()

  Returns the black color component of this color.

  See Also:
    `black`, `getCmykF`, `CMYK Color Model`

### blue

    public final int blue()

  Returns the blue color component of this color.

  See Also:
    `setBlue`, `blueF`, `getRgb`

### blueF

    public final double blueF()

  Returns the blue color component of this color.

  See Also:
    `setBlueF`, `blue`, `getRgbF`

### convertTo

    public final QColor convertTo(QColor.Spec colorSpec)

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

  See Also:
    `spec`, `toCmyk`, `toHsv`, `toRgb`, `isValid`

### cyan

    public final int cyan()

  Returns the cyan color component of this color.

  See Also:
    `cyanF`, `getCmyk`, `CMYK Color Model`

### cyanF

    public final double cyanF()

  Returns the cyan color component of this color.

  See Also:
    `cyan`, `getCmykF`, `CMYK Color Model`

### darker

    public final QColor darker()

  Equivalent to darker(200).

### darker

    public final QColor darker(int f)

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

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

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

  See Also:
    `lighter`, `isValid`

### green

    public final int green()

  Returns the green color component of this color.

  See Also:
    `setGreen`, `greenF`, `getRgb`

### greenF

    public final double greenF()

  Returns the green color component of this color.

  See Also:
    `setGreenF`, `green`, `getRgbF`

### hue

    public final int hue()

  Returns the hue color component of this color.

  See Also:
    `hueF`, `getHsv`, `HSV Color Model`

### hueF

    public final double hueF()

  Returns the hue color component of this color.

  See Also:
    `hue`, `getHsvF`, `HSV Color Model`

### isValid

    public final boolean isValid()

  Returns true if the color is valid; otherwise returns false.

### lighter

    public final QColor lighter()

  Equivalent to lighter(150).

### lighter

    public final QColor lighter(int f)

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

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

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

  See Also:
    `darker`, `isValid`

### magenta

    public final int magenta()

  Returns the magenta color component of this color.

  See Also:
    `magentaF`, `getCmyk`, `CMYK Color Model`

### magentaF

    public final double magentaF()

  Returns the magenta color component of this color.

  See Also:
    `magenta`, `getCmykF`, `CMYK Color Model`

### name

    public final java.lang.String name()

  Returns the name of the color in the format "#RRGGBB"; i.e. a "#" character followed by three two-digit hexadecimal numbers.

  See Also:
    `setNamedColor`

### writeTo

    public final void writeTo(QDataStream arg__1)

  Writes thisQColor to arg__1.

### readFrom

    public final void readFrom(QDataStream arg__1)

  Reads a QColor from arg__1.

### red

    public final int red()

  Returns the red color component of this color.

  See Also:
    `setRed`, `redF`, `getRgb`

### redF

    public final double redF()

  Returns the red color component of this color.

  See Also:
    `setRedF`, `red`, `getRgbF`

### rgb

    public final int rgb()

  Returns the RGB value of the color. The alpha is stripped for compatibility.

  See Also:
    `setRgb`, `getRgb`, `rgba`

### rgba

    public final int rgba()

  Returns the RGB value of the color. Note that unlike `rgb`, the alpha is not stripped.

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

  See Also:
    `setRgba`, `rgb`

### saturation

    public final int saturation()

  Returns the saturation color component of this color.

  See Also:
    `saturationF`, `getHsv`, `HSV Color Model`

### saturationF

    public final double saturationF()

  Returns the saturation color component of this color.

  See Also:
    `saturation`, `getHsvF`, `HSV Color Model`

### setAlpha

    public final void setAlpha(int alpha)

  Sets the alpha of this color to `alpha`. Integer alpha is specified in the range 0-255.

  See Also:
    `alpha`, `alphaF`, `Drawing`

### setAlphaF

    public final void setAlphaF(double alpha)

  Sets the alpha of this color to `alpha`. qreal alpha is specified in the range 0.0-1.0.

  See Also:
    `alphaF`, `alpha`, `Drawing`

### setBlue

    public final void setBlue(int blue)

  Sets the blue color component of this color to `blue`. Int components are specified in the range 0-255.

  See Also:
    `blue`, `blueF`, `setRgb`

### setBlueF

    public final void setBlueF(double blue)

  Sets the blue color component of this color to `blue`. Float components are specified in the range 0.0-1.0.

  See Also:
    `blueF`, `blue`, `setRgbF`

### setCmyk

    public final void setCmyk(int c,
                              int m,
                              int y,
                              int k)

  Equivalent to `setCmyk`(`c`, `m`, `y`, `k`, 255).

### setCmyk

    public final void setCmyk(int c,
                              int m,
                              int y,
                              int k,
                              int a)

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

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

  See Also:
    `getCmyk`, `setCmykF`, `CMYK Color Model`

### setCmykF

    public final void setCmykF(double c,
                               double m,
                               double y,
                               double k)

  Equivalent to `setCmykF`(`c`, `m`, `y`, `k`, 1.0).

### setCmykF

    public final void setCmykF(double c,
                               double m,
                               double y,
                               double k,
                               double a)

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

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

  See Also:
    `getCmykF`, `setCmyk`, `CMYK Color Model`

### setGreen

    public final void setGreen(int green)

  Sets the green color component of this color to `green`. Int components are specified in the range 0-255.

  See Also:
    `green`, `greenF`, `setRgb`

### setGreenF

    public final void setGreenF(double green)

  Sets the green color component of this color to `green`. Float components are specified in the range 0.0-1.0.

  See Also:
    `greenF`, `green`, `setRgbF`

### setHsv

    public final void setHsv(int h,
                             int s,
                             int v)

  Equivalent to `setHsv`(`h`, `s`, `v`, 255).

### setHsv

    public final void setHsv(int h,
                             int s,
                             int v,
                             int a)

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

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

  See Also:
    `getHsv`, `setHsvF`, `HSV Color Model`

### setHsvF

    public final void setHsvF(double h,
                              double s,
                              double v)

  Equivalent to `setHsvF`(`h`, `s`, `v`, 1.0).

### setHsvF

    public final void setHsvF(double h,
                              double s,
                              double v,
                              double a)

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

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

  See Also:
    `getHsvF`, `setHsv`, `HSV Color Model`

### setNamedColor

    public final void setNamedColor(java.lang.String name)

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

  - #RGB (each of R, G, and B is a single hex digit)
  - #RRGGBB
  - #RRRGGGBBB
  - #RRRRGGGGBBBB
  - A name from the list of colors defined in the list of SVG color keyword names provided by the World Wide Web Consortium; for example, "steelblue" or "gainsboro". These color names work on all platforms.
  - `transparent` - representing the absence of a color.
  - X11 only: If allowX11ColorNames() returns true, any valid X11 color name. See the documentation for `XParseColor()` for information about valid X11 color names.

  The color is invalid if `name` cannot be parsed.

  See Also:
    `QColor`, `name`, `isValid`, `allowX11ColorNames`

### setRed

    public final void setRed(int red)

  Sets the red color component of this color to `red`. Int components are specified in the range 0-255.

  See Also:
    `red`, `redF`, `setRgb`

### setRedF

    public final void setRedF(double red)

  Sets the red color component of this color to `red`. Float components are specified in the range 0.0-1.0.

  See Also:
    `redF`, `red`, `setRgbF`

### setRgb

    public final void setRgb(int r,
                             int g,
                             int b)

  Equivalent to `setRgb`(`r`, `g`, `b`, 255).

### setRgb

    public final void setRgb(int r,
                             int g,
                             int b,
                             int a)

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

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

  See Also:
    `rgb`, `getRgb`, `setRgbF`

### setRgb

    public final void setRgb(int rgb)

  Sets the RGB value to `rgb`, ignoring the alpha.

  See Also:
    `rgb`

### setRgbF

    public final void setRgbF(double r,
                              double g,
                              double b)

  Equivalent to `setRgbF`(`r`, `g`, `b`, 1.0).

### setRgbF

    public final void setRgbF(double r,
                              double g,
                              double b,
                              double a)

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

  All values must be in the range 0.0-1.0.

  See Also:
    `rgb`, `getRgbF`, `setRgb`

### setRgba

    public final void setRgba(int rgba)

  Sets the RGBA value to `rgba`. Note that unlike `setRgb`(QRgb rgb), this function does not ignore the alpha.

  See Also:
    `rgba`, `rgb`

### spec

    public final QColor.Spec spec()

  Returns how the color was specified.

  See Also:
    Spec, `convertTo`

### toCmyk

    public final QColor toCmyk()

  Creates and returns a CMYK `QColor` based on this color.

  See Also:
    `fromCmyk`, `convertTo`, `isValid`, `CMYK Color Model`

### toHsv

    public final QColor toHsv()

  Creates and returns an HSV `QColor` based on this color.

  See Also:
    `fromHsv`, `convertTo`, `isValid`, `HSV Color Model`

### toRgb

    public final QColor toRgb()

  Create and returns an RGB `QColor` based on this color.

  See Also:
    `fromRgb`, `convertTo`, `isValid`

### value

    public final int value()

  Returns the value color component of this color.

  See Also:
    `valueF`, `getHsv`, `HSV Color Model`

### valueF

    public final double valueF()

  Returns the value color component of this color.

  See Also:
    `value`, `getHsvF`, `HSV Color Model`

### yellow

    public final int yellow()

  Returns the yellow color component of this color.

  See Also:
    `yellowF`, `getCmyk`, `CMYK Color Model`

### yellowF

    public final double yellowF()

  Returns the yellow color component of this color.

  See Also:
    `yellow`, `getCmykF`, `CMYK Color Model`

### colorNames

    public static java.util.List<java.lang.String> colorNames()

  Returns a `QStringList` containing the color names Qt knows about.

  See Also:
    `Colors`

### fromCmyk

    public static QColor fromCmyk(int c,
                                  int m,
                                  int y,
                                  int k)

  Equivalent to `fromCmyk`(`c`, `m`, `y`, `k`, 255).

### fromCmyk

    public static QColor fromCmyk(int c,
                                  int m,
                                  int y,
                                  int k,
                                  int a)

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

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

  See Also:
    `toCmyk`, `fromCmykF`, `isValid`, `CMYK Color Model`

### fromCmykF

    public static QColor fromCmykF(double c,
                                   double m,
                                   double y,
                                   double k)

  Equivalent to `fromCmykF`(`c`, `m`, `y`, `k`, 1.0).

### fromCmykF

    public static QColor fromCmykF(double c,
                                   double m,
                                   double y,
                                   double k,
                                   double a)

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

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

  See Also:
    `toCmyk`, `fromCmyk`, `isValid`, `CMYK Color Model`

### fromHsv

    public static QColor fromHsv(int h,
                                 int s,
                                 int v)

  Equivalent to `fromHsv`(`h`, `s`, `v`, 255).

### fromHsv

    public static QColor fromHsv(int h,
                                 int s,
                                 int v,
                                 int a)

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

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

  See Also:
    `toHsv`, `fromHsvF`, `isValid`, `HSV Color Model`

### fromHsvF

    public static QColor fromHsvF(double h,
                                  double s,
                                  double v)

  Equivalent to `fromHsvF`(`h`, `s`, `v`, 1.0).

### fromHsvF

    public static QColor fromHsvF(double h,
                                  double s,
                                  double v,
                                  double a)

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

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

  See Also:
    `toHsv`, `fromHsv`, `isValid`, `HSV Color Model`

### fromRgb

    public static QColor fromRgb(int rgb)

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

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

  See Also:
    `fromRgba`, `fromRgbF`, `toRgb`, `isValid`

### fromRgb

    public static QColor fromRgb(int r,
                                 int g,
                                 int b)

  Equivalent to `fromRgb`(`r`, `g`, `b`, 255).

### fromRgb

    public static QColor fromRgb(int r,
                                 int g,
                                 int b,
                                 int a)

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

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

  See Also:
    `toRgb`, `fromRgbF`, `isValid`

### fromRgbF

    public static QColor fromRgbF(double r,
                                  double g,
                                  double b)

  Equivalent to `fromRgbF`(`r`, `g`, `b`, 1.0).

### fromRgbF

    public static QColor fromRgbF(double r,
                                  double g,
                                  double b,
                                  double a)

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

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

  See Also:
    `fromRgb`, `toRgb`, `isValid`

### fromRgba

    public static QColor fromRgba(int rgba)

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

  Note that unlike the `fromRgb` function, the alpha-channel specified by the given QRgb value is included.

  See Also:
    `fromRgb`, `isValid`

### fromNativePointer

    public static QColor fromNativePointer(QNativePointer nativePointer)

  This function returns the QColor instance pointed to by nativePointer

  Parameters:
    `nativePointer` - the QNativePointer of which object should be returned.

### nativePointerArray

    public static QNativePointer nativePointerArray(QColor[] array)

  This function returns a QNativePointer that is pointing to the specified QColor array.

  Parameters:
    `array` - the array that the returned pointer will point to.
  Returns:
    a QNativePointer that is pointing to the specified array.

### equals

    public boolean equals(java.lang.Object other)

  Overrides:
    `equals` in class `java.lang.Object`

### toString

    public java.lang.String toString()

  Returns a string representation of this QColor.

  Overrides:
    `toString` in class `java.lang.Object`

Overview | Package | Class | Tree | Deprecated | Index | Help
Qt Jambi Home |
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD