Qt之图形(简笔画-绘制卡通蚂蚁)

简述

关于简笔画的介绍很多,有动物、水果、蔬菜、交通工具等,通常会对绘制一步步进行拆分、组合。然后绘制为我们想要的结果。

下面来介绍另外的一个种类:昆虫类-卡通蚂蚁。

简述
绘制
效果
源码

绘制

效果

具体的效果如下所示,我们可以再进行更好的完善。

这里写图片描述

源码

主要分为以下三部:

绘制屁股
绘制肚子
绘制头部

注意:绘制的时候,由于各个部分的颜色不同,而且坐标不好定位,所以我们采用的图形覆盖的方式。

void MainWindow::paintEventQPaintEvent *)
{
    QPainter painterthis);
    painter.setRenderHintQPainter :: Antialiasing, true);

    /*****屁股*****/
    QPainterPath path;
    path.addRoundRectQRect200, 60, 150, 150), 1000);
    painter.setBrushQt::white);
    painter.setPenQt::black);
    painter.drawPathpath);

    /*****肚子*****/
    // 腿
    path = QPainterPath);
    path.moveTo170, 180);
    path.lineTo120, 260);
    path.moveTo185, 180);
    path.lineTo145, 280);
    path.moveTo200, 180);
    path.lineTo180, 290);

    path.moveTo200, 180);
    path.lineTo220, 290);
    path.moveTo215, 180);
    path.lineTo250, 280);
    path.moveTo230, 180);
    path.lineTo280, 260);
    painter.setBrushQt::NoBrush);
    painter.setPenQt::white);
    painter.drawPathpath);

    // 肚子
    path = QPainterPath);
    path.addRoundRectQRect150, 130, 100, 100), 1000);
    painter.setBrushQt::white);
    painter.setPenQt::black);
    painter.drawPathpath);

    /*****头*****/
    // 犄角
    path = QPainterPath);
    path.moveTo80, 100);
    path.lineTo60, 20);
    path.moveTo140, 100);
    path.lineTo160, 20);
    painter.setBrushQt::NoBrush);
    painter.setPenQt::white);
    painter.drawPathpath);

    path = QPainterPath);
    path.addRoundRectQRect50, 80, 120, 120), 1000);
    painter.setBrushQt::white);
    painter.setPenQt::black);
    painter.drawPathpath);

    // 左眼
    path = QPainterPath);
    path.addRoundRectQRect70, 120, 25, 25), 1000);
    painter.setBrushQt::black);
    painter.setPenQt::NoPen);
    painter.drawPathpath);

    path = QPainterPath);
    path.addRoundRectQRect75, 126, 10, 10), 1000);
    painter.setBrushQt::white);
    painter.setPenQt::NoPen);
    painter.drawPathpath);

    // 右眼
    path = QPainterPath);
    path.addRoundRectQRect120, 110, 25, 25), 1000);
    painter.setBrushQt::black);
    painter.setPenQt::NoPen);
    painter.drawPathpath);

    path = QPainterPath);
    path.addRoundRectQRect125, 118, 10, 10), 1000);
    painter.setBrushQt::white);
    painter.setPenQt::NoPen);
    painter.drawPathpath);

    // 嘴
    path = QPainterPath);
    path.moveTo160, 108);
    path.arcToQRect130, 48, 60, 60), 270, 100);
    painter.rotate30);
    painter.setBrushQt::NoBrush);
    painter.setPenQt::black);
    painter.drawPathpath);
}

对于一般图形的绘制比较简单,因为常用、有规律,而且比较规则,像圆、椭圆、矩形、直线这些。如果存在各种复杂的图形那么用原生的绘制方案就很难实现了,需要消耗大量的时间来回折腾,所以这里就不再介绍了。

Published by

风君子

独自遨游何稽首 揭天掀地慰生平