我有一个简单的问题,但我还不能解决。
我讨厌这样的事情:
QColor someColor = getColor();
在此之后,我需要获取范围(0-65535)中的颜色代码,请注意,我不需要范围(0-255)中的颜色代码。
那我该怎么做呢?也许像这样:
someColor.get...()
QColor 是 3 个字节 (RGB) 的组合,因此您应该寻找从 0 到 2^24-1 [0, 16777215] 的颜色范围
您可以执行以下操作:
bool ok;
qDebug() << someColor.name().replace("#", "").toUInt(&ok,16);
问候。
Qt已经提供了这样的功能。请参阅此处和此处的文档。
它说什么:
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.