使用QT实现简单艺术字

来源:互联网 发布:华为端口应用acl 编辑:程序博客网 时间:2024/06/12 00:13

    本来这篇文章在前一段时间就该发表的,无奈最近心情一直不太好,今天稍微好了一点,赶紧补上,以作备忘录.

    首先需要明确三点知识:(1)QPen是用来画线条的(2)QBrush是用来填充的 (3)QPainterPath是用来指定绘制路径的。

     不想多说,直接给出代码,具体意思自己思考:

        QPainter pa(mp_image);        QPen myPen;        myPen.setWidth(m_line_width);//线宽        myPen.setColor(m_line_color);//线条颜色        pa.setRenderHint(QPainter::Antialiasing,true); //反交错        pa.setPen(myPen);        //QLinearGradient linearGrad(QPointF(200,0),QPointF(200,0));        QLinearGradient linearGrad;        if(mb_fill_transparent){            linearGrad.setColorAt(0,Qt::transparent); //字体透明 只有边框        }else{            linearGrad.setColorAt(0,m_fill_color);    //字体利用m_fill_color颜色来填充        }        QPainterPath textPath;        textPath.addText(r.left(),r.bottom()-10,m_font,s);        pa.setBrush(linearGrad);        pa.drawPath(textPath);
这样的话就能实现手动的设定文本的线条宽度 颜色,填充区是否透明以及填充区的颜色设定等值。由于时间有限,笔者不能提供测试代码,请读者自行完成,抱歉!




原创粉丝点击