[Interest] QSvgGenerator : Path attribute

Nicholas Yue yue.nicholas at gmail.com
Sun Aug 15 21:46:07 CEST 2021


I think I figured it out. QSvgGenerator handles all of those for us. We
just need to keep in mind the winding rules

```

#include <QApplication>

#include <QPainterPath>

#include <QPainter>

#include <QMap>

#include <QDebug>

#include <QSvgGenerator>


int main(int argc, char **argv)

{

    QString path("nicholas.svg");


    QSvgGenerator generator;

    generator.setFileName(path);

    generator.setSize(QSize(200, 200));

    generator.setViewBox(QRect(0, 0, 200, 200));

    generator.setTitle("SVG Generator Example Drawing");

    generator.setDescription("An SVG drawing created by the SVG Generator "

                             "Example provided with Qt.");


    QPainter painter;

    QColor thrusterColor = Qt::green;

    painter.begin(&generator);


    QPen pen(thrusterColor,4);

    painter.setPen(pen);

    QPainterPath p1;

    p1.moveTo(10,10);

    p1.quadTo(QPointF( 10, 190 ),QPointF( 190, 190 ) );

    p1.quadTo(QPointF(190, 10 ),QPointF(10,10) );

    p1.moveTo(50,50);

    p1.quadTo(QPointF( 150, 50 ),QPointF( 150, 150 ) );

    p1.quadTo(QPointF(50, 150 ),QPointF(50,50) );

    painter.fillPath(p1, thrusterColor);


    painter.end();

}

```


On Sun, 15 Aug 2021 at 10:32, Nicholas Yue <yue.nicholas at gmail.com> wrote:

> Hi,
>
>   I would like to generate SVG via QSvgGenerator with additional attribute
> to the path object
>
> ```
> <path d="M20,20 h200 v160 h-200 Z M80,40 v100 l100,-50 Z" stroke="red"
> stroke-width="2" fill="red" fill-rule="evenodd" />
> ```
>   Where should we be adding such attributes e.g. fill, fill-rule, so that
> QSvgGenerator will embed them in the generated SVG file ?
>
> Cheers
> --
> Nicholas Yue
> https://www.linkedin.com/in/nicholasyue/
>


-- 
Nicholas Yue
https://www.linkedin.com/in/nicholasyue/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210815/82524e96/attachment.html>


More information about the Interest mailing list