我有一个 char[4]
并且我希望能够将它转换成一个 QColor
有没有一种方法可以直接转换而不是这样做:
const char foo[4] = { 128, 128, 128, 128 };
const QColor bar( foo[0], foo[1], foo[2], foo[3] );
最佳答案
我假设你使用的是RGBA,所以你可以使用相应的构造函数:
QColor::QColor(int r, int g, int b, int a = 255)
Constructs a color with the RGB value r, g, b, and the alpha-channel (transparency) value of a.
The color is left invalid if any of the arguments are invalid.
您还可以使用以下静态方法:
QColor QColor::fromRgb(int r, int g, int b, int a = 255) [static]
Static convenience function that returns a QColor constructed from the RGB color values, r (red), g (green), b (blue), and a (alpha-channel, i.e. transparency).
All the values must be in the range 0-255.
关于c++ - char[4] 到 QColor 转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24001664/