Qt realizes the stroke effect of pen and brush

write on top

The so-called stroke effect is actually a thin line with sharp corners formed by the tip of the pen when the pen is lifted up for writing.

Recently, the Qt project has realized the function of a tablet. Among them, the written text has a stroke effect. As shown in the picture below (don’t spray if you don’t like it):

 Implementation code

//在连接处绘制补充点,使其连接处平滑
void drawPatchPoint(QPainter * painter,QPainterPath path)
{
    qreal temp = 3/100.0;
    int k = 0;
    for (qreal i = 0;i < 1; i+=0.01) {
        k++;
        painter->setPen(QPen(Qt::black,4-temp*k, 
                             Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
        painter->drawPoint(path.pointAtPercent(i));
    }
}

The key code has been introduced, if you need specific code, please private message the blogger.

Guess you like

Origin blog.csdn.net/u013015629/article/details/131078143