📄 qcolor.3qt
字号:
'\" t.TH QColor 3qt "11 October 2001" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2001 Trolltech AS. All rights reserved. See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQColor \- Colors based on RGB.PP\fC#include <qcolor.h>\fR.PP.SS "Public Members".in +1c.ti -1c.BI "enum \fBSpec\fR { Rgb, Hsv }".br.ti -1c.BI "\fBQColor\fR ()".br.ti -1c.BI "\fBQColor\fR ( int r, int g, int b )".br.ti -1c.BI "\fBQColor\fR ( int x, int y, int z, Spec colorSpec )".br.ti -1c.BI "\fBQColor\fR ( QRgb rgb, uint pixel = 0xffffffff )".br.ti -1c.BI "\fBQColor\fR ( const QString & name )".br.ti -1c.BI "\fBQColor\fR ( const char * name )".br.ti -1c.BI "\fBQColor\fR ( const QColor & c )".br.ti -1c.BI "QColor & \fBoperator=\fR ( const QColor & c )".br.ti -1c.BI "bool \fBisValid\fR () const".br.ti -1c.BI "QString \fBname\fR () const".br.ti -1c.BI "void \fBsetNamedColor\fR ( const QString & name )".br.ti -1c.BI "void \fBrgb\fR ( int * r, int * g, int * b ) const".br.ti -1c.BI "QRgb \fBrgb\fR () const".br.ti -1c.BI "void \fBsetRgb\fR ( int r, int g, int b )".br.ti -1c.BI "void \fBsetRgb\fR ( QRgb rgb )".br.ti -1c.BI "int \fBred\fR () const".br.ti -1c.BI "int \fBgreen\fR () const".br.ti -1c.BI "int \fBblue\fR () const".br.ti -1c.BI "void \fBhsv\fR ( int * h, int * s, int * v ) const".br.ti -1c.BI "void getHsv ( int & h, int & s, int & v ) const \fI(obsolete)\fR".br.ti -1c.BI "void \fBsetHsv\fR ( int h, int s, int v )".br.ti -1c.BI "QColor \fBlight\fR ( int factor = 150 ) const".br.ti -1c.BI "QColor \fBdark\fR ( int factor = 200 ) const".br.ti -1c.BI "bool \fBoperator==\fR ( const QColor & c ) const".br.ti -1c.BI "bool \fBoperator!=\fR ( const QColor & c ) const".br.ti -1c.BI "uint \fBalloc\fR ()".br.ti -1c.BI "uint \fBpixel\fR () const".br.in -1c.SS "Static Public Members".in +1c.ti -1c.BI "int \fBmaxColors\fR ()".br.ti -1c.BI "int \fBnumBitPlanes\fR ()".br.ti -1c.BI "int \fBenterAllocContext\fR ()".br.ti -1c.BI "void \fBleaveAllocContext\fR ()".br.ti -1c.BI "int \fBcurrentAllocContext\fR ()".br.ti -1c.BI "void \fBdestroyAllocContext\fR ( int context )".br.ti -1c.BI "void \fBinitialize\fR ()".br.ti -1c.BI "void \fBcleanup\fR ()".br.in -1c.SH RELATED FUNCTION DOCUMENTATION.in +1c.ti -1c.BI "QDataStream & \fBoperator<<\fR ( QDataStream & s, const QColor & c )".br.ti -1c.BI "QDataStream & \fBoperator>>\fR ( QDataStream & s, QColor & c )".br.ti -1c.BI "int \fBqRed\fR ( QRgb rgb )".br.ti -1c.BI "int \fBqGreen\fR ( QRgb rgb )".br.ti -1c.BI "int \fBqBlue\fR ( QRgb rgb )".br.ti -1c.BI "int \fBqAlpha\fR ( QRgb rgba )".br.ti -1c.BI "QRgb \fBqRgb\fR ( int r, int g, int b )".br.ti -1c.BI "QRgb \fBqRgba\fR ( int r, int g, int b, int a )".br.ti -1c.BI "int \fBqGray\fR ( int r, int g, int b )".br.ti -1c.BI "int \fBqGray\fR ( qRgb rgb )".br.in -1c.SH DESCRIPTIONThe QColor class provides colors based on RGB..PPA 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)..PPIn 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..PPThe validity (isValid()) 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..PPThere are 19 predefined QColor objects: \fCblack\fR, \fCwhite\fR, \fCdarkGray\fR, \fCgray\fR, \fClightGray\fR, \fCred\fR, \fCgreen\fR, \fCblue\fR, \fCcyan\fR, \fCmagenta\fR, \fCyellow\fR, \fCdarkRed\fR, \fCdarkGreen\fR, \fCdarkBlue\fR, \fCdarkCyan\fR, \fCdarkMagenta\fR, \fCdarkYellow\fR, \fCcolor0\fR and \fCcolor1\fR..PPThe colors \fCcolor0\fR (zero pixel value) and \fCcolor1\fR (non-zero pixel value) are special colors for drawing in bitmaps..PPThe 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 pixel() function is called:.PP<ol type=1>.IP 1Is the pixel value valid? If it is, just return it; otherwise, allocate a pixel value..IP 2Check an internal hash table to see if we allocated an equal RGB value earlier. If we did, set the pixel value and return..IP 3Try 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..IP 4The color could not be allocated. Find the closest matching color and save it in the internal table..PPBecause many people don't know the HSV color model very well, we'll cover it briefly here..PPThe 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 traditional 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..PPHSV, like RGB, has three components:.IP.TPH, 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..IP.TPS, 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..IP.TPV, for value, is 0-255 and represents lightness or brightness of the color. 0 is black; 255 is as far from black as possible..IP.PPHere 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..PPQt 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..PPA color can be set by passing setNamedColor() 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 light() and dark() respectively. Colors can also be set using setRgb() and setHsv(). The color components can be accessed in one go with rgb() and hsv(), or individually with red(), green() and blue()..PPUse maxColors() and numBitPlanes() to determine the maximum number of colors and the number of bit planes supported by the underlying window system,.PPIf you need to allocate many colors temporarily, for example in an image viewer application, enterAllocContext(), leaveAllocContext() and destroyAllocContext() will prove useful..PPSee also QPalette, QColorGroup, QApplication::setColorSpec(), Color FAQ, Widget Appearance and Style, Graphics Classes and Image Processing Classes..SS "Member Type Documentation".SH "QColor::Spec"The type of color specified, either RGB or HSV, e.g. in the \fCQColor::QColor( x, y, z, colorSpec)\fR constructor..TP\fCQColor::Rgb\fR.TP\fCQColor::Hsv\fR.SH MEMBER FUNCTION DOCUMENTATION.SH "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..PPThe alpha value of an invalid color is unspecified..PPSee also isValid()..SH "QColor::QColor ( int r, int g, int b )"Constructs a color with the RGB value \fIr\fR, \fIg\fR, \fIb\fR, in the same way as setRgb()..PPThe color is left invalid if any or the arguments are illegal..PPSee also setRgb()..SH "QColor::QColor ( int x, int y, int z, Spec colorSpec )"Constructs a color with the RGB or HSV value \fIx\fR, \fIy\fR, \fIz\fR..PPThe arguments are an RGB value if \fIcolorSpec\fR is QColor::Rgb. \fIx\fR (red), \fIy\fR (green), and \fIz\fR (blue). All of them must be in the range 0-255..PPThe arguments are an HSV value if \fIcolorSpec\fR is QColor::Hsv. \fIx\fR (hue) must be -1 for achromatic colors and 0-359 for chromatic colors; \fIy\fR (saturation) and \fIz\fR (value) must both be in the range 0-255..PPSee also setRgb() and setHsv()..SH "QColor::QColor ( QRgb rgb, uint pixel = 0xffffffff )"Constructs a color with the RGB value \fIrgb\fR and a custom pixel value \fIpixel\fR..PPIf \fIpixel\fR == 0xffffffff (the default), then the color uses the RGB value in a standard way. If \fIpixel\fR is something else, then the pixel value is set directly to \fIpixel\fR, skipping the normal allocation procedure..SH "QColor::QColor ( const QString & name )"Constructs a named color in the same way as setNamedColor() using name \fIname\fR..PPSee also setNamedColor()..SH "QColor::QColor ( const char * name )"Constructs a named color in the same way as setNamedColor() using name \fIname\fR..PPSee also setNamedColor()..SH "QColor::QColor ( const QColor & c )"Constructs a color that is a copy of \fIc\fR..SH "uint QColor::alloc ()"Allocates the RGB color and returns the pixel value..PPAllocating 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..PPThe pixel() function calls alloc() if necessary, so in general you don't need to call this function..PPSee also enterAllocContext()..SH "int QColor::blue () const"Returns the B (blue) component of the RGB value..SH "void QColor::cleanup ()\fC [static]\fR"Internal clean up required for QColor. This function is called from the QApplication destructor..PPSee also initialize()..SH "int QColor::currentAllocContext ()\fC [static]\fR"Returns the current color allocation context..PPThe default context is 0..PPSee also enterAllocContext() and leaveAllocContext()..SH "QColor QColor::dark ( int factor = 200 ) const"Returns a darker (or lighter) color, but does not change this object.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -