Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QColor Class

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

Header:#include <QColor>

Public Types

enumSpec { Rgb, Hsv, Cmyk, Hsl, Invalid }

Public Functions

QColor()
QColor(int r, int g, int b, int a = 255)
QColor(QRgb color)
QColor(const QString & name)
QColor(const char * name)
QColor(const QColor & color)
QColor(Qt::GlobalColor color)
intalpha() const
qrealalphaF() const
intblack() const
qrealblackF() const
intblue() const
qrealblueF() const
QColorconvertTo(Spec colorSpec) const
intcyan() const
qrealcyanF() const
QColordarker(int factor = 200) const
voidgetCmyk(int * c, int * m, int * y, int * k, int * a = 0)
voidgetCmykF(qreal * c, qreal * m, qreal * y, qreal * k, qreal * a = 0)
voidgetHsl(int * h, int * s, int * l, int * a = 0) const
voidgetHslF(qreal * h, qreal * s, qreal * l, qreal * a = 0) const
voidgetHsv(int * h, int * s, int * v, int * a = 0) const
voidgetHsvF(qreal * h, qreal * s, qreal * v, qreal * a = 0) const
voidgetRgb(int * r, int * g, int * b, int * a = 0) const
voidgetRgbF(qreal * r, qreal * g, qreal * b, qreal * a = 0) const
intgreen() const
qrealgreenF() const
inthslHue() const
qrealhslHueF() const
inthslSaturation() const
qrealhslSaturationF() const
inthsvHue() const
qrealhsvHueF() const
inthsvSaturation() const
qrealhsvSaturationF() const
inthue() const
qrealhueF() const
boolisValid() const
QColorlighter(int factor = 150) const
intlightness() const
qreallightnessF() const
intmagenta() const
qrealmagentaF() const
QStringname() const
intred() const
qrealredF() const
QRgbrgb() const
QRgbrgba() const
intsaturation() const
qrealsaturationF() const
voidsetAlpha(int alpha)
voidsetAlphaF(qreal alpha)
voidsetBlue(int blue)
voidsetBlueF(qreal blue)
voidsetCmyk(int c, int m, int y, int k, int a = 255)
voidsetCmykF(qreal c, qreal m, qreal y, qreal k, qreal a = 1.0)
voidsetGreen(int green)
voidsetGreenF(qreal green)
voidsetHsl(int h, int s, int l, int a = 255)
voidsetHslF(qreal h, qreal s, qreal l, qreal a = 1.0)
voidsetHsv(int h, int s, int v, int a = 255)
voidsetHsvF(qreal h, qreal s, qreal v, qreal a = 1.0)
voidsetNamedColor(const QString & name)
voidsetRed(int red)
voidsetRedF(qreal red)
voidsetRgb(int r, int g, int b, int a = 255)
voidsetRgb(QRgb rgb)
voidsetRgbF(qreal r, qreal g, qreal b, qreal a = 1.0)
voidsetRgba(QRgb rgba)
Specspec() const
QColortoCmyk() const
QColortoHsl() const
QColortoHsv() const
QColortoRgb() const
intvalue() const
qrealvalueF() const
intyellow() const
qrealyellowF() const
operator QVariant() const
booloperator!=(const QColor & color) const
QColor &operator=(const QColor & color)
QColor &operator=(Qt::GlobalColor color)
booloperator==(const QColor & color) const

Static Public Members

boolallowX11ColorNames()
QStringListcolorNames()
QColorfromCmyk(int c, int m, int y, int k, int a = 255)
QColorfromCmykF(qreal c, qreal m, qreal y, qreal k, qreal a = 1.0)
QColorfromHsl(int h, int s, int l, int a = 255)
QColorfromHslF(qreal h, qreal s, qreal l, qreal a = 1.0)
QColorfromHsv(int h, int s, int v, int a = 255)
QColorfromHsvF(qreal h, qreal s, qreal v, qreal a = 1.0)
QColorfromRgb(QRgb rgb)
QColorfromRgb(int r, int g, int b, int a = 255)
QColorfromRgbF(qreal r, qreal g, qreal b, qreal a = 1.0)
QColorfromRgba(QRgb rgba)
boolisValidColor(const QString & name)
voidsetAllowX11ColorNames(bool enabled)

Related Non-Members

typedefQRgb
intqAlpha(QRgb rgba)
intqBlue(QRgb rgb)
intqGray(int r, int g, int b)
intqGray(QRgb rgb)
intqGreen(QRgb rgb)
intqRed(QRgb rgb)
QRgbqRgb(int r, int g, int b)
QRgbqRgba(int r, int g, int b, int a)
QDataStream &operator<<(QDataStream & stream, const QColor & color)
QDataStream &operator>>(QDataStream & stream, QColor & color)

Detailed Description

TheQColor 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.

RGBHSVCMYK

TheQColor constructor creates the color based on RGB values. To create aQColor based on either HSV or CMYK values, use thetoHsv() andtoCmyk() functions respectively. These functions return a copy of the color using the desired format. In addition the staticfromRgb(),fromHsv() andfromCmyk() functions create colors from the specified values. Alternatively, a color can be converted to any of the three formats using theconvertTo() function (returning a copy of the color in the desired format), or any of thesetRgb(),setHsv() andsetCmyk() functions alteringthis color's format. Thespec() 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 thesetNamedColor() function. The color names are taken from the SVG 1.0 color names. Thename() function returns the name of the color in the format "#RRGGBB". Colors can also be set usingsetRgb(),setHsv() andsetCmyk(). To get a lighter or darker color use thelighter() anddarker() functions respectively.

TheisValid() function indicates whether aQColor 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 withred(),hue() andcyan(). The values of the color components can also be retrieved in one go using thegetRgb(),getHsv() andgetCmyk() functions. Using the RGB color model, the color components can in addition be accessed withrgb().

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 theAlpha-Blended Drawing section). TheqRed(),qBlue() andqGreen() functions return the respective component of the givenQRgb value, while theqRgb() andqRgba() functions create and return theQRgb triplet based on the given component values. Finally, theqAlpha() function returns the alpha component of the providedQRgb, and theqGray() function calculates and return a gray value based on the given value.

QColor is platform and device independent. TheQColormap class maps the color to the hardware.

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

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() andfromCmykF(). 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 thegetRgbF() function due to rounding.

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

Alpha-Blended Drawing

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

// Specify semi-transparent redpainter.setBrush(QColor(255,0,0,127));painter.drawRect(0,0, width()/2, height());// Specify semi-transparent bluepainter.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 thealpha() andsetAlpha() functions if its value is an integer, andalphaF() andsetAlphaF() if its value is qreal (double). By default, the alpha-channel is set to 255 (opaque). To retrieve and setall the RGB color components (including the alpha-channel) in one go, use thergba() andsetRgba() functions.

Predefined Colors

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

Qt Colors

Additionally, theQt::color0,Qt::color1 andQt::transparent colors are used for special purposes.

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

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

The HSV Color Model

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

HSV, like RGB, has three components:

  • 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 featurealpha-blended drawing.

The HSL Color Model

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

The CMYK Color Model

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

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

Mixing 100 percent of cyan, magenta and yellowdoes 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 featurealpha-blended drawing.

See alsoQPalette,QBrush, andQApplication::setColorSpec().

Member Type Documentation

enum QColor::Spec

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

ConstantValue
QColor::Rgb1
QColor::Hsv2
QColor::Cmyk3
QColor::Hsl4
QColor::Invalid0

See alsospec() andconvertTo().

Member Function Documentation

QColor::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 alsoisValid().

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

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

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

See alsosetRgba() andisValid().

QColor::QColor(QRgb color)

Constructs a color with the valuecolor. The alpha component is ignored and set to solid.

See alsofromRgb() andisValid().

QColor::QColor(constQString & name)

Constructs a named color in the same way assetNamedColor() using the givenname.

The color is left invalid if thename cannot be parsed.

See alsosetNamedColor(),name(), andisValid().

QColor::QColor(constchar * name)

Constructs a named color in the same way assetNamedColor() using the givenname.

The color is left invalid if thename cannot be parsed.

See alsosetNamedColor(),name(), andisValid().

QColor::QColor(constQColor & color)

Constructs a color that is a copy ofcolor.

See alsoisValid().

QColor::QColor(Qt::GlobalColor color)

This is an overloaded function.

Constructs a new color with a color value ofcolor.

See alsoisValid() andPredefined Colors.

[static]bool QColor::allowX11ColorNames()

Returns true ifsetNamedColor() is allowed to look up colors in the X11 color database. By default, this function returns false.

Note:This function is only available on the X11 platform.

See alsosetAllowX11ColorNames().

int QColor::alpha() const

Returns the alpha color component of this color.

See alsosetAlpha(),alphaF(), andAlpha-Blended Drawing.

qreal QColor::alphaF() const

Returns the alpha color component of this color.

See alsosetAlphaF(),alpha(), andAlpha-Blended Drawing.

int QColor::black() const

Returns the black color component of this color.

See alsoblackF(),getCmyk(), andThe CMYK Color Model.

qreal QColor::blackF() const

Returns the black color component of this color.

See alsoblack(),getCmykF(), andThe CMYK Color Model.

int QColor::blue() const

Returns the blue color component of this color.

See alsosetBlue(),blueF(), andgetRgb().

qreal QColor::blueF() const

Returns the blue color component of this color.

See alsosetBlueF(),blue(), andgetRgbF().

[static]QStringList QColor::colorNames()

Returns aQStringList containing the color names Qt knows about.

See alsoPredefined Colors.

QColor QColor::convertTo(Spec colorSpec) const

Creates a copy ofthis color in the format specified bycolorSpec.

See alsospec(),toCmyk(),toHsv(),toRgb(), andisValid().

int QColor::cyan() const

Returns the cyan color component of this color.

See alsocyanF(),getCmyk(), andThe CMYK Color Model.

qreal QColor::cyanF() const

Returns the cyan color component of this color.

See alsocyan(),getCmykF(), andThe CMYK Color Model.

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

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

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

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

This function was introduced in Qt 4.3.

See alsolighter() andisValid().

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

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

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

See alsotoCmyk(),fromCmykF(),isValid(), andThe CMYK Color Model.

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

This is an overloaded function.

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

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

See alsotoCmyk(),fromCmyk(),isValid(), andThe CMYK Color Model.

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

Static convenience function that returns aQColor constructed from the HSV color values,h (hue),s (saturation),l (lightness), anda (alpha-channel, i.e. transparency).

The value ofs,l, anda must all be in the range 0-255; the value ofh must be in the range 0-359.

This function was introduced in Qt 4.6.

See alsotoHsl(),fromHslF(), andisValid().

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

This is an overloaded function.

Static convenience function that returns aQColor constructed from the HSV color values,h (hue),s (saturation),l (lightness), anda (alpha-channel, i.e. transparency).

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

This function was introduced in Qt 4.6.

See alsotoHsl(),fromHsl(), andisValid().

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

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

The value ofs,v, anda must all be in the range 0-255; the value ofh must be in the range 0-359.

See alsotoHsv(),fromHsvF(),isValid(), andThe HSV Color Model.

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

This is an overloaded function.

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

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

See alsotoHsv(),fromHsv(),isValid(), andThe HSV Color Model.

[static]QColor QColor::fromRgb(QRgb rgb)

Static convenience function that returns aQColor constructed from the givenQRgb valuergb.

The alpha component ofrgb is ignored (i.e. it is automatically set to 255), use thefromRgba() function to include the alpha-channel specified by the givenQRgb value.

See alsofromRgba(),fromRgbF(),toRgb(), andisValid().

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

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

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

See alsotoRgb(),fromRgbF(), andisValid().

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

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

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

See alsofromRgb(),toRgb(), andisValid().

[static]QColor QColor::fromRgba(QRgb rgba)

Static convenience function that returns aQColor constructed from the givenQRgb valuergba.

Unlike thefromRgb() function, the alpha-channel specified by the givenQRgb value is included.

See alsofromRgb() andisValid().

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

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

These components can be retrieved individually using thecyan(),magenta(),yellow(),black() andalpha() functions.

See alsosetCmyk() andThe CMYK Color Model.

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

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

These components can be retrieved individually using thecyanF(),magentaF(),yellowF(),blackF() andalphaF() functions.

See alsosetCmykF() andThe CMYK Color Model.

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

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

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

This function was introduced in Qt 4.6.

See alsosetHsl().

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

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

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

This function was introduced in Qt 4.6.

See alsosetHsl().

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

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

These components can be retrieved individually using thehue(),saturation(),value() andalpha() functions.

See alsosetHsv() andThe HSV Color Model.

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

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

These components can be retrieved individually using thehueF(),saturationF(),valueF() andalphaF() functions.

See alsosetHsv() andThe HSV Color Model.

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

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

These components can be retrieved individually using thered(),green(),blue() andalpha() functions.

See alsorgb() andsetRgb().

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

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

These components can be retrieved individually using theredF(),greenF(),blueF() andalphaF() functions.

See alsorgb() andsetRgb().

int QColor::green() const

Returns the green color component of this color.

See alsosetGreen(),greenF(), andgetRgb().

qreal QColor::greenF() const

Returns the green color component of this color.

See alsosetGreenF(),green(), andgetRgbF().

int QColor::hslHue() const

Returns the hue color component of this color.

This function was introduced in Qt 4.6.

See alsogetHslF() andgetHsl().

qreal QColor::hslHueF() const

Returns the hue color component of this color.

This function was introduced in Qt 4.6.

See alsohue() andgetHslF().

int QColor::hslSaturation() const

Returns the saturation color component of this color.

This function was introduced in Qt 4.6.

See alsosaturationF(),getHsv(), andThe HSV Color Model.

qreal QColor::hslSaturationF() const

Returns the saturation color component of this color.

This function was introduced in Qt 4.6.

See alsosaturationF() andgetHslF().

int QColor::hsvHue() const

Returns the hue color component of this color.

See alsohueF(),getHsv(), andThe HSV Color Model.

qreal QColor::hsvHueF() const

Returns the hue color component of this color.

See alsohue(),getHsvF(), andThe HSV Color Model.

int QColor::hsvSaturation() const

Returns the saturation color component of this color.

See alsosaturationF(),getHsv(), andThe HSV Color Model.

qreal QColor::hsvSaturationF() const

Returns the saturation color component of this color.

See alsosaturation(),getHsvF(), andThe HSV Color Model.

int QColor::hue() const

Returns the hue color component of this color.

The color is implicitly converted to HSV.

See alsohsvHue(),hueF(),getHsv(), andThe HSV Color Model.

qreal QColor::hueF() const

Returns the hue color component of this color.

The color is implicitly converted to HSV.

See alsohsvHueF(),hue(),getHsvF(), andThe HSV Color Model.

bool QColor::isValid() const

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

[static]bool QColor::isValidColor(constQString & name)

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

It uses the same algorithm used insetNamedColor().

This function was introduced in Qt 4.7.

See alsosetNamedColor().

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

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

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

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

This function was introduced in Qt 4.3.

See alsodarker() andisValid().

int QColor::lightness() const

Returns the lightness color component of this color.

This function was introduced in Qt 4.6.

See alsolightnessF() andgetHsl().

qreal QColor::lightnessF() const

Returns the lightness color component of this color.

This function was introduced in Qt 4.6.

See alsovalue() andgetHslF().

int QColor::magenta() const

Returns the magenta color component of this color.

See alsomagentaF(),getCmyk(), andThe CMYK Color Model.

qreal QColor::magentaF() const

Returns the magenta color component of this color.

See alsomagenta(),getCmykF(), andThe CMYK Color Model.

QString QColor::name() const

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

See alsosetNamedColor().

int QColor::red() const

Returns the red color component of this color.

See alsosetRed(),redF(), andgetRgb().

qreal QColor::redF() const

Returns the red color component of this color.

See alsosetRedF(),red(), andgetRgbF().

QRgb QColor::rgb() const

Returns the RGB value of the color. The alpha value is opaque.

See alsosetRgb(),getRgb(), andrgba().

QRgb QColor::rgba() const

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

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

See alsosetRgba() andrgb().

int QColor::saturation() const

Returns the saturation color component of this color.

The color is implicitly converted to HSV.

See alsohsvSaturation(),saturationF(),getHsv(), andThe HSV Color Model.

qreal QColor::saturationF() const

Returns the saturation color component of this color.

The color is implicitly converted to HSV.

See alsohsvSaturationF(),saturation(),getHsvF(), andThe HSV Color Model.

[static]void QColor::setAllowX11ColorNames(bool enabled)

AllowsetNamedColor() to look up colors in the X11 color database ifenabled. By default,setNamedColor() doesnot look up colors in the X11 color database.

Note:This function is only available on the X11 platform.

See alsosetNamedColor() andallowX11ColorNames().

void QColor::setAlpha(int alpha)

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

See alsoalpha(),alphaF(), andAlpha-Blended Drawing.

void QColor::setAlphaF(qreal alpha)

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

See alsoalphaF(),alpha(), andAlpha-Blended Drawing.

void QColor::setBlue(int blue)

Sets the blue color component of this color toblue. Integer components are specified in the range 0-255.

See alsoblue(),blueF(), andsetRgb().

void QColor::setBlueF(qreal blue)

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

See alsoblueF(),blue(), andsetRgbF().

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

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

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

See alsogetCmyk(),setCmykF(), andThe CMYK Color Model.

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

This is an overloaded function.

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

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

See alsogetCmykF(),setCmyk(), andThe CMYK Color Model.

void QColor::setGreen(int green)

Sets the green color component of this color togreen. Integer components are specified in the range 0-255.

See alsogreen(),greenF(), andsetRgb().

void QColor::setGreenF(qreal green)

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

See alsogreenF(),green(), andsetRgbF().

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

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

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

This function was introduced in Qt 4.6.

See alsogetHsl() andsetHslF().

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

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

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

This function was introduced in Qt 4.6.

See alsogetHslF() andsetHsl().

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

Sets a HSV color value;h is the hue,s is the saturation,v is the value anda 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 alsohsv(),getHsv(),setHsvF(), andThe HSV Color Model.

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

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

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

See alsogetHsvF(),setHsv(), andThe HSV Color Model.

void QColor::setNamedColor(constQString & name)

Sets the RGB value of thisQColor toname, 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 ofSVG color keyword names provided by the World Wide Web Consortium; for example, "steelblue" or "gainsboro". These color names work on all platforms. Note that these color names arenot the same as defined by theQt::GlobalColor enums, e.g. "green" andQt::green does not refer to the same color.
  • transparent - representing the absence of a color.
  • X11 only: IfallowX11ColorNames() returns true, any valid X11 color name. See the documentation forXParseColor() for information about valid X11 color names.

The color is invalid ifname cannot be parsed.

See alsoQColor(),name(),isValid(), andallowX11ColorNames().

void QColor::setRed(int red)

Sets the red color component of this color tored. Integer components are specified in the range 0-255.

See alsored(),redF(), andsetRgb().

void QColor::setRedF(qreal red)

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

See alsoredF(),red(), andsetRgbF().

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

Sets the RGB value tor,g,b and the alpha value toa.

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

See alsorgb(),getRgb(), andsetRgbF().

void QColor::setRgb(QRgb rgb)

This is an overloaded function.

Sets the RGB value torgb. The alpha value is set to opaque.

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

Sets the color channels of this color tor (red),g (green),b (blue) anda (alpha, transparency).

All values must be in the range 0.0-1.0.

See alsorgb(),getRgbF(), andsetRgb().

void QColor::setRgba(QRgb rgba)

Sets the RGB value torgba, including its alpha.

See alsorgba() andrgb().

Spec QColor::spec() const

Returns how the color was specified.

See alsoSpec andconvertTo().

QColor QColor::toCmyk() const

Creates and returns a CMYKQColor based on this color.

See alsofromCmyk(),convertTo(),isValid(), andThe CMYK Color Model.

QColor QColor::toHsl() const

Creates and returns an HSLQColor based on this color.

See alsofromHsl(),convertTo(), andisValid().

QColor QColor::toHsv() const

Creates and returns an HSVQColor based on this color.

See alsofromHsv(),convertTo(),isValid(), andThe HSV Color Model.

QColor QColor::toRgb() const

Create and returns an RGBQColor based on this color.

See alsofromRgb(),convertTo(), andisValid().

int QColor::value() const

Returns the value color component of this color.

See alsovalueF(),getHsv(), andThe HSV Color Model.

qreal QColor::valueF() const

Returns the value color component of this color.

See alsovalue(),getHsvF(), andThe HSV Color Model.

int QColor::yellow() const

Returns the yellow color component of this color.

See alsoyellowF(),getCmyk(), andThe CMYK Color Model.

qreal QColor::yellowF() const

Returns the yellow color component of this color.

See alsoyellow(),getCmykF(), andThe CMYK Color Model.

QColor::operator QVariant() const

Returns the color as aQVariant

bool QColor::operator!=(constQColor & color) const

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

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

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

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

This is an overloaded function.

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

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

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

Related Non-Members

typedefQRgb

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

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

See alsoQColor::rgb() andQColor::rgba().

intqAlpha(QRgb rgba)

Returns the alpha component of the ARGB quadrupletrgba.

See alsoqRgb() andQColor::alpha().

intqBlue(QRgb rgb)

Returns the blue component of the ARGB quadrupletrgb.

See alsoqRgb() andQColor::blue().

intqGray(int r,int g,int b)

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

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

intqGray(QRgb rgb)

This is an overloaded function.

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

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

intqGreen(QRgb rgb)

Returns the green component of the ARGB quadrupletrgb.

See alsoqRgb() andQColor::green().

intqRed(QRgb rgb)

Returns the red component of the ARGB quadrupletrgb.

See alsoqRgb() andQColor::red().

QRgbqRgb(int r,int g,int b)

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

See alsoqRgba(),qRed(),qGreen(), andqBlue().

QRgbqRgba(int r,int g,int b,int a)

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

See alsoqRgb(),qRed(),qGreen(), andqBlue().

QDataStream &operator<<(QDataStream & stream, constQColor & color)

Writes thecolor to thestream.

See alsoSerializing Qt Data Types.

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

Reads thecolor from thestream.

See alsoSerializing Qt Data Types.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp