閱讀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)