QColor Class ReferenceThe QColor class provides colors based on RGB, HSV or CMYK values. Далее... #include <QColor>
Открытые типы
Открытые функции
Статические открытые члены
Подробное описание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.
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. Для получения дополнительной информации о матрице преобразований смотрите документацию по Система рисования. Integer vs. Floating Point PrecisionQColor 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) изображений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. Например: // Specify semi-transparent red painter.setBrush(QColor(255, 0, 0, 127)); painter.drawRect(0, 0, width()/2, height()); // Specify semi-transparent blue painter.setBrush(QColor(0, 0, 255, 127)); painter.drawRect(0, 0, width(), height()/2); Данный код приведет к отображению следующего растрового рисунка: Рисование с использованием альфа-смешивания поддерживается в системах Windows, Mac OS X и в X11 с установленным расширением X Render. 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 ColorsThere are 20 predefined QColors described by the Qt::GlobalColor enum, including black, white, primary and secondary colors, darker versions of these colors and three shades of gray. QColor also recognizes a variety of color names; the static colorNames() function returns a QStringList color names that QColor knows about. Additionally, the Qt::color0, Qt::color1 and Qt::transparent colors are used for special purposes. Qt::color0 (zero pixel value) and Qt::color1 (non-zero pixel value) are special colors for drawing in QBitmaps. Painting with Qt::color0 sets the bitmap bits to 0 (transparent; i.e., background), and painting with Qt::color1 sets the bits to 1 (opaque; i.e., foreground). Qt::transparent is used to indicate a transparent pixel. When painting with this value, a pixel value will be used that is appropriate for the underlying pixel format in use. The HSV Color ModelThe RGB model is hardware-oriented. Its representation is close to what most monitors show. In contrast, HSV represents color in a way more suited to the human perception of color. For example, the relationships "stronger than", "darker than", and "the opposite of" are easily expressed in HSV but are much harder to express in RGB. HSV, like RGB, has three components:
Here are some examples: pure red is H=0, S=255, V=255; a dark red, moving slightly towards the magenta, could be H=350 (equivalent to -10), S=255, V=180; a grayish light red could have H about 0 (say 350-359 or 0-10), S about 50-100, and S=255. Qt returns a hue value of -1 for achromatic colors. If you pass a hue value that is too large, Qt forces it into range. Hue 360 or 720 is treated as 0; hue 540 is treated as 180. In addition to the standard HSV model, Qt provides an alpha-channel to feature alpha-blended drawing. The HSL Color ModelHSL 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 ModelWhile 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, and QApplication::setColorSpec(). Описание функций-членовQColor::QColor ()QColor::QColor ( Qt::GlobalColor color )QColor::QColor ( int r, int g, int b, int a = 255 )QColor::QColor ( QRgb rgb )QColor::QColor ( const QString & name )QColor::QColor ( const char * name )QColor::QColor ( const QColor & color )QColor::QColor ( Spec spec )bool QColor::allowX11ColorNames () [static]See also setAllowX11ColorNames(). int QColor::alpha () constSee also setAlpha(). qreal QColor::alphaF () constSee also setAlphaF(). int QColor::black () constqreal QColor::blackF () constint QColor::blue () constSee also setBlue(). qreal QColor::blueF () constSee also setBlueF(). QStringList QColor::colorNames () [static]QColor QColor::convertTo ( Spec colorSpec ) constint QColor::cyan () constqreal QColor::cyanF () constQColor QColor::dark ( int f = 200 ) constQColor QColor::darker ( int f = 200 ) constQColor QColor::fromCmyk ( int c, int m, int y, int k, int a = 255 ) [static]QColor QColor::fromCmykF ( qreal c, qreal m, qreal y, qreal k, qreal a = 1.0 ) [static]QColor QColor::fromHsl ( int h, int s, int l, int a = 255 ) [static]QColor QColor::fromHslF ( qreal h, qreal s, qreal l, qreal a = 1.0 ) [static]QColor QColor::fromHsv ( int h, int s, int v, int a = 255 ) [static]QColor QColor::fromHsvF ( qreal h, qreal s, qreal v, qreal a = 1.0 ) [static]QColor QColor::fromRgb ( QRgb rgb ) [static]QColor QColor::fromRgb ( int r, int g, int b, int a = 255 ) [static]QColor QColor::fromRgbF ( qreal r, qreal g, qreal b, qreal a = 1.0 ) [static]QColor QColor::fromRgba ( QRgb rgba ) [static]void QColor::getCmyk ( int * c, int * m, int * y, int * k, int * a = 0 )void QColor::getCmykF ( qreal * c, qreal * m, qreal * y, qreal * k, qreal * a = 0 )void QColor::getHsl ( int * h, int * s, int * l, int * a = 0 ) constvoid QColor::getHslF ( qreal * h, qreal * s, qreal * l, qreal * a = 0 ) constvoid QColor::getHsv ( int * h, int * s, int * v, int * a = 0 ) constvoid QColor::getHsvF ( qreal * h, qreal * s, qreal * v, qreal * a = 0 ) constvoid QColor::getRgb ( int * r, int * g, int * b, int * a = 0 ) constvoid QColor::getRgbF ( qreal * r, qreal * g, qreal * b, qreal * a = 0 ) constint QColor::green () constSee also setGreen(). qreal QColor::greenF () constSee also setGreenF(). int QColor::hslHue () constqreal QColor::hslHueF () constint QColor::hslSaturation () constqreal QColor::hslSaturationF () constint QColor::hsvHue () constqreal QColor::hsvHueF () constint QColor::hsvSaturation () constqreal QColor::hsvSaturationF () constint QColor::hue () constqreal QColor::hueF () constbool QColor::isValid () constbool QColor::isValidColor ( const QString & name ) [static]QColor QColor::light ( int f = 150 ) constQColor QColor::lighter ( int f = 150 ) constint QColor::lightness () constqreal QColor::lightnessF () constint QColor::magenta () constqreal QColor::magentaF () constQString QColor::name () constint QColor::red () constSee also setRed(). qreal QColor::redF () constSee also setRedF(). QRgb QColor::rgb () constSee also setRgb(). QRgb QColor::rgba () constSee also setRgba(). int QColor::saturation () constqreal QColor::saturationF () constvoid QColor::setAllowX11ColorNames ( bool enabled ) [static]See also allowX11ColorNames(). void QColor::setAlpha ( int alpha )See also alpha(). void QColor::setAlphaF ( qreal alpha )See also alphaF(). void QColor::setBlue ( int blue )See also blue(). void QColor::setBlueF ( qreal blue )See also blueF(). void QColor::setCmyk ( int c, int m, int y, int k, int a = 255 )void QColor::setCmykF ( qreal c, qreal m, qreal y, qreal k, qreal a = 1.0 )void QColor::setGreen ( int green )See also green(). void QColor::setGreenF ( qreal green )See also greenF(). void QColor::setHsl ( int h, int s, int l, int a = 255 )void QColor::setHslF ( qreal h, qreal s, qreal l, qreal a = 1.0 )void QColor::setHsv ( int h, int s, int v, int a = 255 )See also hsv(). void QColor::setHsvF ( qreal h, qreal s, qreal v, qreal a = 1.0 )void QColor::setNamedColor ( const QString & name )void QColor::setRed ( int red )See also red(). void QColor::setRedF ( qreal red )See also redF(). void QColor::setRgb ( int r, int g, int b, int a = 255 )See also rgb(). void QColor::setRgb ( QRgb rgb )void QColor::setRgbF ( qreal r, qreal g, qreal b, qreal a = 1.0 )void QColor::setRgba ( QRgb rgba )See also rgba(). Spec QColor::spec () constQColor QColor::toCmyk () constQColor QColor::toHsl () constQColor QColor::toHsv () constQColor QColor::toRgb () constint QColor::value () constqreal QColor::valueF () constint QColor::yellow () constqreal QColor::yellowF () constQColor::operator QVariant () constbool QColor::operator!= ( const QColor & c ) constQColor & QColor::operator= ( const QColor & )QColor & QColor::operator= ( Qt::GlobalColor color )bool QColor::operator== ( const QColor & c ) const |
Попытка перевода Qt документации. Если есть желание присоединиться, или если есть замечания или пожелания, то заходите на форум: Перевод Qt документации на русский язык... Люди внесшие вклад в перевод: Команда переводчиков |