• Qt QSVG使用详解


           SVG 伸缩可矢量图形(SVG)是一种基于XML的语言,用于描述二维矢量图形。SVG 使用 XML 格式定义图像。

    Qt QSVG使用详解目录

    1 SVG基本格式

    2 加载SVG矢量图

    3 生成矢量图

     4 矢量图下载网站

    4.1 阿里巴巴

    4.2 Lineicons

     4.3 ionicons

     5 下载地址


            本文作者原创,转载请附上文章出处与本文链接。

    1 SVG基本格式

            以下示例出自 iconfont 阿里巴巴矢量图

    1. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
    2. <path d="M256 0C114.6 0 0 114.6 0 256s114.6 256 256 256s256-114.6 256-256S397.4 0 256 0zM256 464c-114.7 0-208-93.31-208-208S141.3 48 256 48s208 93.31 208 208S370.7 464 256 464zM255.1 176C255.1 176 255.1 176 255.1 176c21.06 0 40.92 8.312 55.83 23.38c9.375 9.344 24.53 9.5 33.97 .1562c9.406-9.344 9.469-24.53 .1562-33.97c-24-24.22-55.95-37.56-89.95-37.56c0 0 .0313 0 0 0c-33.97 0-65.95 13.34-89.95 37.56c-49.44 49.88-49.44 131 0 180.9c24 24.22 55.98 37.56 89.95 37.56c.0313 0 0 0 0 0c34 0 65.95-13.34 89.95-37.56c9.312-9.438 9.25-24.62-.1562-33.97c-9.438-9.312-24.59-9.219-33.97 .1562c-14.91 15.06-34.77 23.38-55.83 23.38c0 0 .0313 0 0 0c-21.09 0-40.95-8.312-55.89-23.38c-30.94-31.22-30.94-82.03 0-113.3C214.2 184.3 234 176 255.1 176z"/>
    3. svg>

    2 加载SVG矢量图

    1. QSvgRenderer render;
    2. render.load (QString("D:/copyright.svg"));
    3. QSize size = render.defaultSize ();
    4. QPixmap *pix = new QPixmap(30, 30);
    5. //QPixmap pix(size*5); // 可以在这儿直接缩放处理
    6. pix->fill (Qt::transparent); // 像素清空
    7. QPainter painter(pix);
    8. painter.setRenderHints (QPainter::Antialiasing);
    9. render.render (&painter);
    10. ui->pushButton->setIcon(QIcon(*pix));
    11. ui->pushButton->setIconSize(QSize(30, 30));
    12. ui->pushButton->setFlat(true);
    13. //ui->pushButton->setStyleSheet("border: 0px"); //消除边框

    3 生成矢量图

    1. QSvgGenerator generator; // 定义SVG的产生器
    2. generator.setFileName (QString("temp.svg")); // 设置SVG文件名
    3. generator.setDescription ("Test QSvgGenerator"); // 无所谓
    4. QSize size(400,400);
    5. generator.setSize (size); // 设置大小
    6. generator.setViewBox(QRect(0, 0, 400, 400)); // 视口大小
    7. QPainter painter; // 小画家
    8. painter.begin (&generator);
    9. QRect rect(0,0,400,400);
    10. painter.setBrush (Qt::cyan);
    11. painter.drawEllipse (rect); // 直接在 generator 上绘制 一个圆
    12. painter.end (); // 需要保证绘制结束
    1. "1.0" encoding="UTF-8" standalone="no"?>
    2. <svg width="141.111mm" height="141.111mm"
    3. viewBox="0 0 400 400"
    4. xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.2" baseProfile="tiny">
    5. <title>Qt SVG Documenttitle>
    6. <desc>Test QSvgGeneratordesc>
    7. <defs>
    8. defs>
    9. <g fill="none" stroke="black" stroke-width="1" fill-rule="evenodd" stroke-linecap="square" stroke-linejoin="bevel" >
    10. <g fill="#00ffff" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="square" stroke-linejoin="bevel" transform="matrix(1,0,0,1,0,0)"
    11. font-family="SimSun" font-size="9" font-weight="400" font-style="normal"
    12. >
    13. <circle cx="200" cy="200" r="200"/>
    14. g>
    15. g>
    16. svg>

     4 矢量图下载网站

    4.1 阿里巴巴

    阿里巴巴官方矢量图网站: iconfont-阿里巴巴矢量图标库

    4.2 Lineicons

    Free Line Icons for Designers and Developers - Lineicons

     

     4.3 ionicons

    Ionicons: Premium Open Source Icon Pack for Ionic Framework

     5 下载地址

    本博客源代码下载地址:QSVG使用Demo程序-C++文档类资源-CSDN下载

    20多个最佳 ICON 库_高先生的猫的博客-CSDN博客_icon库

  • 相关阅读:
    STL list合并
    Verlog-串口发送-FPGA
    [安洵杯 2019]easy_web md5强碰撞 preg_match绕过
    mySQL—基础SQL语句
    Aardio - 通过变量名将变量值整合到一串文本中
    抓包分析 TCP 握手和挥手
    Vue常用知识点汇总
    牛客网刷题-(1)
    一文看懂 ZooKeeper ,面试再也不用背八股
    基于 Next.js实现在线Excel
  • 原文地址:https://blog.csdn.net/qq_37529913/article/details/126428075