QColor::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.
color对象里头的alpha其实是指不透明度,其值范围为0-255,越大越不透明。
其通常对应opacity,这个就是单词语义表达的不透明度,其值范围[0,1.0f],值越大,越不透明。
opacity与alpha的映射
100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
65% — A6
60% — 99
55% — 8C
50% — 80
45% — 73
40% — 66
35% — 59
30% — 4D
25% — 40
20% — 33
15% — 26
10% — 1A
5% — 0D
0% — 00
int alpha = Math.round(opacity * 255);
String hex = Integer.toHexString(alpha).toUpperCase();
if (hex.length() == 1){
hex = "0" + hex;
}
Qt::GlobalColor
The QColor class provides colors based on RGB, HSV or CMYK values.
Constant | Value | Description |
Qt::white | 3 | White (#ffffff) |
Qt::black | 2 | Black (#000000) |
Qt::red | 7 | Red (#ff0000) |
Qt::darkRed | 13 | Dark red (#800000) |
Qt::green | 8 | Green (#00ff00) |
Qt::darkGreen | 14 | Dark green (#008000) |
Qt::blue | 9 | Blue (#0000ff) |
Qt::darkBlue | 15 | Dark blue (#000080) |
Qt::cyan | 10 | Cyan (#00ffff) |
Qt::darkCyan | 16 | Dark cyan (#008080) |
Qt::magenta | 11 | Magenta (#ff00ff) |
Qt::darkMagenta | 17 | Dark magenta (#800080) |
Qt::yellow | 12 | Yellow (#ffff00) |
Qt::darkYellow | 18 | Dark yellow (#808000) |
Qt::gray | 5 | Gray (#a0a0a4) |
Qt::darkGray | 4 | Dark gray (#808080) |
Qt::lightGray | 6 | Light gray (#c0c0c0) |
Qt::transparent | 19 | a transparent black value (i.e., QColor(0, 0, 0, 0)) |
Qt::color0 | 0 | 0 pixel value (for bitmaps) |
Qt::color1 | 1 | 1 pixel value (for bitmaps) |