Qt中设置透明橡皮擦方法,通过setCompositionMode(QPainter::CompositionMode_Clear)
来实现。
Qpainter *painter;
painter->setRenderHint(QPainter::Antialiasing,true);
if(m_isdraw == true)//判断是书写笔还是橡皮
{painter->setCompositionMode(QPainter::CompositionMode_SourceOver); painter->setPen(element->m_pen); }
else{
painter->setCompositionMode(QPainter::CompositionMode_Clear);}//橡皮擦设置为擦除并为透明色。
painter->drawPath(path); //然后画图。