QPixmap tmpPix(pix.size());
tmpPix.fill(Qt::transparent);
QPainter p1(&tmpPix);
p1.setCompositionMode(QPainter::CompositionMode_Source);
p1.drawPixmap(0, 0, pix);
if (canBuild)//可建则用半透明表示
{
//200表示透明度,数值0表示完全透明,数值255表示不透明
p1.setCompositionMode(QPainter::CompositionMode_DestinationIn);
p1.fillRect(tmpPix.rect(), QColor(0, 0, 0, 200));
}
else//不可建则用红色半透明表示
{
p1.setCompositionMode(QPainter::CompositionMode_ColorBurn);
p1.fillRect(tmpPix.rect(), QColor(255, 100, 100, 200));
}
p1.end();
pix = tmpPix;
painter->drawPixmap(fzX1 - NODE_WIDTH + thisBuilding.x_draw, fzY1 + NODE_HEIGHT + thisBuilding.y_draw, pix);
先上一段网上差不多的代码,将就看,没那么多时间写帖子
CompositionMode_DestinationIn
CompositionMode_ColorBurn
CompositionMode_ColorDodge
CompositionMode_Darken
CompositionMode_Destination
CompositionMode_DestinationAtop
CompositionMode_DestinationOut
CompositionMode_DestinationOver
CompositionMode_Difference
CompositionMode_Exclusion
CompositionMode_HardLight
CompositionMode_Lighten
CompositionMode_Multiply
CompositionMode_Overlay
CompositionMode_Plus
CompositionMode_Screen
CompositionMode_SoftLight
CompositionMode_Source
CompositionMode_SourceAtop 取交集
CompositionMode_SourceIn
CompositionMode_SourceOut 这种就直接挖空了
CompositionMode_SourceOver
CompositionMode_Xor