设置一个叠加的透明颜色
QColor qgroundColor = QColor(128, 128, 128, 128); //叠加初始颜色
QColor tgroundColor = QColor("#ffffff");
//具体的填充颜色
__int64 nFillColor = //等于某一个颜色值
tgroundColor .setRgb(nFillColor);
QColor color = getNewColor(tgroundColor , qgroundColor );
float calculateRGBAValue(const float fTranslucent1, const float fTranslucent2, const float RGBVlue1, const float RGBVlue2) const
{
return (RGBVlue1 * fTranslucent1 * (1.0 - fTranslucent2) + RGBVlue2 * fTranslucent2) / (fTranslucent1 + fTranslucent2 - fTranslucent1 * fTranslucent2); //计算两个叠加后的值
}
const QColor getNewColor(const QColor& backgroundColor, const QColor& foregroundColor) const
{
//处理叠加的RGB和透明度
//处理两种颜色叠加时透明度a-alpha值
float fTranslucent1 = backgroundColor.alpha() / 255.0;
float fTranslucent2 = foregroundColor.alpha() / 255.0;
float fTranslucent = fTranslucent1 + fTranslucent2 - fTranslucent1 * fTranslucent2;
//计算R-Red值
float fRed1 = backgroundColor.red() / 255.0;
float fRed2 = foregroundColor.red() / 255.0;
float fRed = calculateRGBAValue(fTranslucent1, fTranslucent2, fRed1, fRed2);
//计算G - Green值
float fGreen1 = backgroundColor.green() / 255.0;
float fGreen2 = foregroundColor.green() / 255.0;
float fGreen = calculateRGBAValue(fTranslucent1, fTranslucent2, fGreen1, fGreen2);
//计算B - Blue值
float fBlue1 = backgroundColor.blue() / 255.0;
float fBlue2 = foregroundColor.blue() / 255.0;
float fBlue = calculateRGBAValue(fTranslucent1, fTranslucent2, fBlue1, fBlue2);
return QColor(fRed * 255, fGreen * 255, fBlue * 255, fTranslucent * 255);
}