Qt:QtPainter设置画笔

1060 篇文章 307 订阅
#include <QPainter>
#include <QFont>
void MainWindow::paintEvent(QPaintEvent *)
{
    QPainter painter;
    painter.begin(this);

    QPen pen(Qt::black);
    pen.setStyle(Qt::SolidLine);
    pen.setWidth(20);

    QPointF p1[3] = {
        QPointF(30.0, 80.0),QPointF(20.0, 40.0), QPointF(80.0, 60.0)
    };
    QPointF p2[3] = {
        QPointF(130.0, 80.0), QPointF(120.0, 40.0), QPointF(180.0, 60.0)
    };
    QPointF p3[3] = {
        QPointF(230.0, 80.0), QPointF(220.0, 40.0), QPointF(280.0, 60.0)
    };

    pen.setJoinStyle(Qt::MiterJoin);
    painter.setPen(pen);
    painter.drawPolyline(p1, 3);

    pen.setJoinStyle(Qt::BevelJoin);
    painter.setPen(pen);
    painter.drawPolyline(p2, 3);

    pen.setJoinStyle(Qt::RoundJoin);
    painter.setPen(pen);
    painter.drawPolyline(p3, 3);

    painter.end();
}

8d2bc65ac0164a48a7b132bd3175d26e411.jpg

画笔的连接风格

#include <QPainter>
#include <QFont>
void MainWindow::paintEvent(QPaintEvent *)
{
    QPainter painter;
    painter.begin(this);


    QPen pen(Qt::black);
    pen.setStyle(Qt::SolidLine);
    pen.setWidth(20);

        pen.setCapStyle(Qt::FlatCap);
        painter.setPen(pen);
        painter.drawLine(30, 30, 200, 30);

        pen.setCapStyle(Qt::SquareCap);
        painter.setPen(pen);
        painter.drawLine(30, 70, 200, 70);

        pen.setCapStyle(Qt::RoundCap);
        painter.setPen(pen);
        painter.drawLine(30, 110, 200, 110);

    painter.end();
}

6deff8ab4e913c5b4f28ff7f45ceb6f6b53.jpg

画笔的三种边角。

void MainWindow::paintEvent(QPaintEvent *)
{
    QPainter painter;
    painter.begin(this);

    QRect rect1(10.0, 20.0, 80.0, 50);
    QRect rect2(110.0, 20.0, 80.0, 50.0);
    QRect rect3(210.0, 20.0, 80.0, 50.0);
    QRect rect4(10.0, 100.0, 80.0, 50.0);
    QRect rect5(110.0, 100.0, 80.0, 50.0);
    QRect rect6(210.0, 100.0, 80.0, 50.0);

        QPen pen(Qt::blue, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
        painter.setPen(pen);
        painter.drawEllipse(rect1);  //画椭圆

        pen.setStyle(Qt::DashLine);
        painter.setPen(pen);
        painter.drawEllipse(rect2);

        pen.setStyle(Qt::DotLine);
        painter.setPen(pen);

        painter.drawEllipse(rect3);

        pen.setStyle(Qt::DashDotLine);
        painter.setPen(pen);

        painter.drawEllipse(rect4);

        pen.setStyle(Qt::DashDotDotLine);
        painter.setPen(pen);
        painter.drawEllipse(rect5);

        pen.setStyle(Qt::CustomDashLine);
        painter.setPen(pen);
        painter.drawEllipse(rect6);
    painter.end();
}

045ea8dc64d0c145fadc0bde52fb70b238c.jpg

设置画笔的轮廓

--

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值