使用光栅操作
// 背景色取反
painter.setCompositionMode( QPainter::RasterOp_SourceAndNotDestination );
画笔必须设置为白色
/// 设置画笔用白色(必须为白色)
painter.setPen( Qt::white );
// 绘制线条
painter.drawLine( QPoint(0,0), rect().bottomRight()) ;
// 绘制文字
painter.drawText( rect(), Qt::AlignCenter, "hello raster\nhello qt" );
效果:取反色的图片和文字、线
取反色的线和文字