Results 1 to 5 of 5

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

  1. #1
    Join Date
    Feb 2016
    Posts
    5
    Qt products
    Qt5

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

    This is how i try to render SVG:

    Qt Code:
    1. void DialogImageProperies::showSVG(QString sFile){
    2. this->adjustSize();
    3.  
    4. QSvgRenderer rndr(sFile);
    5. QPixmap px;
    6. QSizeF szSvgF = rndr.defaultSize();
    7.  
    8. if (szSvgF.width() > szSvgF.height())
    9. {
    10. px = QPixmap(1000, int(qreal(1000 )* szSvgF.height()/szSvgF.width()));
    11. }
    12. else
    13. {
    14. px = QPixmap(int(qreal(1000 )* szSvgF.width()/szSvgF.height()), 1000 );
    15. }
    16.  
    17.  
    18. QPainter p(&px);
    19. rndr.render(&p);
    20.  
    21. ui->wdgBck->setPixmap(px);
    22. this->exec();
    23. }
    To copy to clipboard, switch view to plain text mode 

    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:
    svg_orig.jpg

    That is what i get:
    30xF1.jpg

    For now i see no way to deal with all it...
    Last edited by Songg; 28th February 2016 at 15:56. Reason: corect image insertion

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

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

    Have you investigated the viewBoxF() of the loaded SVG?

  3. #3
    Join Date
    Feb 2016
    Posts
    5
    Qt products
    Qt5

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

    Quote Originally Posted by ChrisW67 View Post
    Have you investigated the viewBoxF() of the loaded SVG?
    No. ViewBox is not what i looking for. For my case they are the same:

    Qt Code:
    1. void DialogImageProperies::showSVG(QSvgRenderer &rndr,QString sFile){
    2.  
    3. qd << "defaultSize - " << rndr.defaultSize();
    4. qd << "viewBoxF - " << rndr.viewBoxF();
    To copy to clipboard, switch view to plain text mode 

    And console output :

    Qt Code:
    1. src\dlgImgProp.cpp 52 defaultSize - QSize(1250, 961)
    2. src\dlgImgProp.cpp 53 viewBoxF - QRectF(0,0 1250x961.25)
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2016
    Posts
    5
    Qt products
    Qt5

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

    Solution (or workaround? doesn't matter)

    This is svg begin:
    <?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)))

  5. #5
    Join Date
    Feb 2016
    Posts
    5
    Qt products
    Qt5

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

    Solution:
    Need to manually delete "width", "height", "viewBox" attributes from <svg> element. Then Qt not found predefined boundaries and calculate them by itself.

Similar Threads

  1. Rendering items to graphicsscene
    By hema in forum Newbie
    Replies: 1
    Last Post: 20th July 2011, 08:43
  2. Rendering order of items in a QwtPlot
    By citocran in forum Qwt
    Replies: 1
    Last Post: 7th January 2011, 16:47
  3. QGridLayout: how to know it has finished rendering items?
    By slash_blog in forum Qt Programming
    Replies: 0
    Last Post: 8th June 2010, 13:06
  4. Replies: 8
    Last Post: 1st October 2009, 11:07
  5. Rendering items on QListView
    By rcintra in forum Qt Programming
    Replies: 6
    Last Post: 10th May 2007, 23:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.