我有一个简单的问题,但我还无法解决。
我喜欢这样的事情:
QColor someColor = getColor();
在此之后,我需要获得范围(0-65535)内的颜色代码,我注意到我不需要范围内的颜色代码(0-255)。
那么我必须做什么? 也许是这样的:
someColor.get...()
答案 0 :(得分:1)
QColor是3个字节(RGB)的组合,因此您应该寻找0到2 ^ 24-1 [0,16777215]的颜色范围
您可以执行以下操作:
bool ok;
qDebug() << someColor.name().replace("#", "").toUInt(&ok,16);
问候。
答案 1 :(得分:1)
Qt already provides such function. See documentation here and here.
What it says:
QRgb QColor::rgb() const
// Returns the RGB value of the color. The alpha value is opaque.
QRgb QColor::rgba() const
// Returns the RGB value of the color, including its alpha.
typedef QRgb
// An ARGB quadruplet on the format #AARRGGBB, equivalent to an unsigned int.
// The type also holds a value for the alpha-channel.