前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Qt自绘-冰墩墩

Qt自绘-冰墩墩

作者头像
Qt君
发布2023-03-17 15:24:02
2681
发布2023-03-17 15:24:02
举报
文章被收录于专栏:跟Qt君学编程

闲着没事干,肝个冰墩墩吧。使用QPainter绘制实现,源代码在末尾。

效果:

源码:

代码语言:javascript
复制
class BingDwenDwen : public QWidget
{
    Q_OBJECT
protected:
    void paintEvent(QPaintEvent *e) 
    {
        QPainter painter(this);
        painter.setRenderHint(QPainter::Antialiasing);

        QPainterPath path0;
        path0.moveTo(312, 270);
        path0.cubicTo(331, 284, 354, 284, 367, 271);
        painter.drawPath(path0);

        QPainterPath path1;
        path1.moveTo(312, 271);
        path1.cubicTo(333, 277, 353, 286, 367, 270);
        painter.drawPath(path1);

        painter.setPen(QPen(QColor("#2f4f4f"), 1));

        QPainterPath path2;
        path2.moveTo(251, 238);
        path2.cubicTo(253, 270, 316, 266, 296, 218);
        painter.drawPath(path2);

        QPainterPath path3;
        path3.moveTo(250, 237);
        path3.cubicTo(254, 199, 293, 212, 296, 217);
        painter.drawPath(path3);

        QPainterPath path4;
        path4.moveTo(393, 255);
        path4.cubicTo(418, 257, 438, 215, 398, 208);
        painter.drawPath(path4);

        painter.setPen(QPen(QColor("#000000"), 1));

        QPainterPath path5;
        path5.moveTo(393, 255);
        path5.cubicTo(365, 244, 372, 202, 398, 208);
        painter.drawPath(path5);

        painter.setPen(QPen(QColor("#000000"), 2));

        QPainterPath path6;
        path6.moveTo(249, 86);
        path6.cubicTo(197, 59, 152, 115, 176, 154);
        painter.drawPath(path6);

        QPainterPath path7;
        path7.moveTo(250, 88);
        path7.cubicTo(284, 64, 375, 67, 395, 81);
        painter.drawPath(path7);

        QPainterPath path8;
        path8.moveTo(395, 82);
        path8.cubicTo(417, 54, 490, 66, 458, 135);
        painter.drawPath(path8);

        QPainterPath path9;
        path9.moveTo(458, 136);
        path9.cubicTo(472, 151, 491, 174, 492, 200);
        painter.drawPath(path9);

        QPainterPath path10;
        path10.moveTo(177, 157);
        path10.cubicTo(146, 191, 140, 238, 137, 281);
        painter.drawPath(path10);

        QPainterPath path11;
        path11.moveTo(136, 283);
        path11.cubicTo(47, 389, 72, 440, 120, 423);
        painter.drawPath(path11);

        QPainterPath path12;
        path12.moveTo(120, 423);
        path12.cubicTo(151, 406, 141, 382, 149, 370);
        painter.drawPath(path12);

        QPainterPath path13;
        path13.moveTo(149, 372);
        path13.cubicTo(164, 429, 192, 421, 197, 556);
        painter.drawPath(path13);

        QPainterPath path14;
        path14.moveTo(198, 556);
        path14.cubicTo(229, 584, 300, 567, 291, 550);
        painter.drawPath(path14);

        QPainterPath path15;
        path15.moveTo(309, 519);
        path15.cubicTo(286, 515, 277, 535, 291, 549);
        painter.drawPath(path15);

        QPainterPath path16;
        path16.moveTo(310, 518);
        path16.cubicTo(320, 521, 338, 510, 329, 553);
        painter.drawPath(path16);

        QPainterPath path17;
        path17.moveTo(329, 555);
        path17.cubicTo(356, 590, 435, 573, 427, 546);
        painter.drawPath(path17);

        QPainterPath path18;
        path18.moveTo(499, 316);
        path18.cubicTo(477, 470, 431, 409, 428, 546);
        painter.drawPath(path18);

        QPainterPath path19;
        path19.moveTo(499, 315);
        path19.cubicTo(662, 212, 531, 116, 490, 202);
        painter.drawPath(path19);

        QPainterPath path20;
        path20.moveTo(207, 474);
        path20.cubicTo(220, 542, 196, 568, 279, 550);
        painter.drawPath(path20);

        QPainterPath path21;
        path21.moveTo(207, 474);
        path21.cubicTo(329, 517, 264, 516, 278, 550);
        painter.drawPath(path21);

        QPainterPath path22;
        path22.moveTo(339, 522);
        path22.cubicTo(345, 555, 369, 564, 412, 546);
        painter.drawPath(path22);

        QPainterPath path23;
        path23.moveTo(338, 520);
        path23.cubicTo(430, 472, 440, 440, 413, 547);
        painter.drawPath(path23);

        QPainterPath path24;
        path24.moveTo(139, 297);
        path24.cubicTo(47, 389, 112, 473, 147, 363);
        painter.drawPath(path24);

        QPainterPath path25;
        path25.moveTo(505, 291);
        path25.cubicTo(618, 225, 539, 124, 500, 212);
        painter.drawPath(path25);

        QPainterPath path26;
        path26.moveTo(329, 243);
        path26.cubicTo(328, 251, 358, 262, 364, 241);
        painter.drawPath(path26);

        QPainterPath path27;
        path27.moveTo(329, 243);
        path27.cubicTo(328, 226, 367, 234, 364, 242);
        painter.drawPath(path27);

        QPainterPath path28;
        path28.moveTo(500, 213);
        path28.cubicTo(500, 234, 512, 261, 504, 291);
        painter.drawPath(path28);

        QPainterPath path29;
        path29.moveTo(219, 281);
        path29.cubicTo(245, 319, 352, 239, 299, 192);
        painter.drawPath(path29);

        QPainterPath path30;
        path30.moveTo(219, 280);
        path30.cubicTo(180, 245, 255, 175, 298, 192);
        painter.drawPath(path30);

        QPainterPath path31;
        path31.moveTo(365, 219);
        path31.cubicTo(391, 292, 452, 312, 458, 273);
        painter.drawPath(path31);

        QPainterPath path32;
        path32.moveTo(364, 219);
        path32.cubicTo(379, 149, 464, 214, 456, 273);
        painter.drawPath(path32);

        QPainterPath path33;
        path33.moveTo(140, 298);
        path33.cubicTo(137, 327, 145, 347, 148, 362);
        painter.drawPath(path33);

        painter.setPen(QPen(QColor("#00ffff"), 4));

        QPainterPath path34;
        path34.moveTo(285, 121);
        path34.cubicTo(76, 208, 185, 413, 330, 404);
        painter.drawPath(path34);

        QPainterPath path35;
        path35.moveTo(289, 120);
        path35.cubicTo(523, 76, 567, 413, 333, 405);
        painter.drawPath(path35);

        painter.setPen(QPen(QColor("#6a5acd"), 4));

        QPainterPath path36;
        path36.moveTo(284, 129);
        path36.cubicTo(77, 219, 206, 415, 335, 399);
        painter.drawPath(path36);

        QPainterPath path37;
        path37.moveTo(285, 129);
        path37.cubicTo(525, 78, 548, 415, 338, 400);
        painter.drawPath(path37);

        painter.setPen(QPen(QColor("#ff4500"), 4));

        QPainterPath path38;
        path38.moveTo(189, 286);
        path38.cubicTo(254, 461, 489, 384, 476, 275);
        painter.drawPath(path38);

        QPainterPath path39;
        path39.moveTo(189, 283);
        path39.cubicTo(155, 103, 468, 62, 476, 272);
        painter.drawPath(path39);

        painter.setPen(QPen(QColor("#ffd700"), 4));

        QPainterPath path40;
        path40.moveTo(240, 344);
        path40.cubicTo(388, 451, 573, 287, 403, 154);
        painter.drawPath(path40);

        QPainterPath path41;
        path41.moveTo(238, 342);
        path41.cubicTo(100, 188, 313, 94, 400, 152);
        painter.drawPath(path41);

        painter.setPen(QPen(QColor("#adff2f"), 4));

        QPainterPath path42;
        path42.moveTo(401, 357);
        path42.cubicTo(240, 410, 134, 238, 253, 165);
        painter.drawPath(path42);

        QPainterPath path43;
        path43.moveTo(255, 164);
        path43.cubicTo(440, 70, 531, 320, 404, 357);
        painter.drawPath(path43);
    }
};

// 使用
BingDwenDwen b;
b.setWindowTitle("Qt自绘-冰墩墩");
b.resize(650, 650);
b.show();
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2022-03-15,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Qt君 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 效果:
  • 源码:
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档