阅读521 返回首页    go 阿里云 go 技术社区[云栖]


QColor与Int类型相互转换

下面介绍怎么将QColor与int进行相互转换

1、在头文件中添加以下代码:

#include <QColor> int QColorToInt(const QColor &color); QColor IntToQColor(const int &intColor);

2、在主体CPP文件中添加以下转换函数:

int BenQWord::QColorToInt(const QColor &color) { //将Color 从QColor 转换成 int return (int)(((unsigned int)color.blue()<< 16) | (unsigned short)(((unsigned short)color.green()<< 8) | color.red())); } QColor BenQWord::IntToQColor(const int &intColor) { //将Color 从int 转换成 QColor int red = intColor & 255; int green = intColor >> 8 & 255; int blue = intColor >> 16 & 255; return QColor(red, green, blue); }

最后更新:2017-04-02 04:01:45

  上一篇:go Writing Use Case Extensions
  下一篇:go 挑战淘宝:且看如何用1500行搞定淘宝20000行Java SDK(1)