user3444737
user3444737

Reputation: 41

QSvgRenderer - correct rendering of svg-items despite of defaultSize()?

That is how i try to render SVG:

void DialogImageProperies::showSVG(QString sFile){
    this->adjustSize();

    QSvgRenderer rndr(sFile);   
    QPixmap px;
    QSizeF szSvgF = rndr.defaultSize();

    if (szSvgF.width() > szSvgF.height())
    {
        px = QPixmap(1000, int(qreal(1000 )* szSvgF.height()/szSvgF.width()));
    }
    else
    {
        px = QPixmap(int(qreal(1000 )* szSvgF.width()/szSvgF.height()), 1000 );
    }


    QPainter p(&px);
    rndr.render(&p);

    ui->wdgBck->setPixmap(px);
    this->exec();
}

But as for me, i never notice what is a size of canvas in any created by myself vector-image. So, i think that users also will not predefine correct boundaries.

That is how SVG looks in Inkscape - Inkscape That is what i get - rendered

For now i see no way to workaround all it...

Upvotes: 0

Views: 763

Answers (1)

user3444737
user3444737

Reputation: 41

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->

<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   id="svg2"
   version="1.1"
   inkscape:version="0.91 r13725"
   sodipodi:docname="hhhhhhhhhhh_slide2.svg"
   **width="1250"**
   **height="961.25"**>
  <defs
     id="defs4" />
  <sodipodi:namedview
.......
......

If manually delete width="1250" and height="961.25" then Qt recalculate real itemsBoundingRect of svg)))

Upvotes: 1

Related Questions