c++ - char[4] 到 QColor 转换

标签 c++ qt colors qtgui qcolor

我有一个 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/

相关文章:

c++ - 使用自定义比较器模板化自定义容器

linux - 应用程序以退出代码 126 完成

c++ - 在 Qt 中使用 GPS 检索手机的位置

html - 同一页面中的多个 SVG 问题 - 消失和颜色变化

c++ - 在 C++ 中使用 XGBOOST

c++ - 如何将模板构造函数特化移动到 cpp 文件?

c++ - fatal error : X11/extensions/XIproto. h : No such file or directory #include <X11/extensions/XIproto. h>

iphone - 根据 iPhone 颜色更改颜色

r - 在 ggplot2 中使用 scale_color_manual 时,中断和值在图中不匹配

c++ - 编译问题C++