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