qt 绘制多多边形

绘制多多边形

void CutImg::paintEvent(QPaintEvent *)
{

//    static const QPoint points[4] = {
//        QPoint(10, 80),
//        QPoint(20, 10),
//        QPoint(80, 30),
//        QPoint(90, 70)
//    };

    static const QPoint points[4] = {
        QPoint(530, 3969),
        QPoint(715, 3743),
        QPoint(775, 3816),
        QPoint(699, 4024)
    };

    static const QPoint points_1[3] = {
        QPoint(26, 3298),
        QPoint(271, 3144),
        QPoint(194, 3529)
    };

    QPolygon py,py1;
    for(int i=0;i<4;i++)
    {
        py.push_back(points[i]);
    }
    for(int i=0;i<3;i++)
    {
        py1.push_back(points_1[i]);
    }

    QPainter painter(this);

    int width = 1;
    Qt::PenStyle style = Qt::PenStyle(1);
    Qt::PenCapStyle cap = Qt::PenCapStyle(0);
    Qt::PenJoinStyle join = Qt::PenJoinStyle(0);
    painter.setPen(QPen(Qt::blue, width, style, cap, join));

    //Qt::BrushStyle styleBrush = Qt::BrushStyle(15);
    //QLinearGradient linearGradient(0, 0, 100, 100);
    QLinearGradient linearGradient(0, 0, this->width(), this->height());
    linearGradient.setColorAt(0.0, Qt::white);
    //linearGradient.setColorAt(0.2, Qt::green);
    linearGradient.setColorAt(0.2, QColor("#8000FF00"));
    linearGradient.setColorAt(1.0, Qt::black);
    painter.setBrush(linearGradient);
    painter.setRenderHint(QPainter::Antialiasing, true);

                painter.save();
                painter.translate(0, 0);
                //painter.drawPolygon(points, 4);
                painter.drawPolygon(py);
                painter.restore();

                painter.save();
                painter.translate(0, 0);
                //painter.drawPolygon(points_1, 3);
                painter.drawPolygon(py1);
                painter.restore();

//    for (int x = 0; x < this->width(); x += 100) {
//        for (int y = 0; y < this->height(); y += 100) {
//            painter.save();
//            painter.translate(x, y);
//            painter.drawPolygon(points, 4);
//            painter.restore();
//        }
//    }

    painter.setRenderHint(QPainter::Antialiasing, false);
    painter.setPen(palette().dark().color());
    painter.setBrush(Qt::NoBrush);
    painter.drawRect(QRect(0, 0, this->width() - 1, this->height() - 1));
}

效果:

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值