Results 1 to 3 of 3

Thread: Border cutting with QGraphicsSvgItem

  1. #1
    Join Date
    Feb 2007
    Location
    Italy
    Posts
    69
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Border cutting with QGraphicsSvgItem

    Hi there,
    Today I was enjoying with Graphics View and SVG. I'm not expert with this framework, so maybe I messed up something
    Here's the problem:
    i setup a graphic view for svg, with svg renderer and item, but I noticed that - leaving everything untransformed - the edges of my svg shape are cutted off:
    http://www.ale-re.net/images/softwares/border-cut.png
    the original file was made with inkscape, this one:
    http://www.ale-re.net/images/softwares/test.svg

    The code is this:
    Qt Code:
    1. #include <QApplication>
    2. #include <QSvgRenderer>
    3. #include <QGraphicsView>
    4. #include <QGraphicsScene>
    5. #include <QGraphicsSvgItem>
    6. #include <QBrush>
    7.  
    8. int main(int argc, char **argv) {
    9. QApplication app(argc, argv);
    10. // Create a renderer for this svg file
    11. QSvgRenderer *svgRend = new QSvgRenderer(QLatin1String("test.svg"));
    12. // Create a scene where set things
    13. // Use a custom brush for the background
    14. QBrush bgBrush(QColor(32, 32, 32), Qt::SolidPattern);
    15. scene.setBackgroundBrush(bgBrush);
    16. // Create svg item for the scene
    17. svg->setSharedRenderer(svgRend);
    18. svg->setElementId(QLatin1String("shape"));
    19. // Add the item to the scene
    20. scene.addItem(svg);
    21. // Initialize the view
    22. QGraphicsView view(&scene);
    23. view.show();
    24. return app.exec();
    25. }
    To copy to clipboard, switch view to plain text mode 
    I tried to translate/scale/rotate the item - if i'm not wrong, these should affect the item matrix, so the item only would change - but no results: the borders still seems cutted.
    If you try to add
    Qt Code:
    1. svg->rotate(5.0);
    To copy to clipboard, switch view to plain text mode 
    you can notice that borders are still cutted... It seems that bounding box is calculated without considering borders, so they are cutted.

    Any idea?

    Thanks very much!

    p.s. well, as you can also notice, there is also an issue with text, which isn't put on multi-lines, but this is another issue

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Border cutting with QGraphicsSvgItem

    How about if you resize the item with QGraphicsItem::setSize() ?
    Is the ID passed to setElementId the root SVG element?

  3. #3
    Join Date
    Feb 2007
    Location
    Italy
    Posts
    69
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Border cutting with QGraphicsSvgItem

    I don't have QGraphicsItem::setSize() - using 4.2.3

    main.cpp:22: error: 'class QGraphicsSvgItem' has no member named 'setSize'

    and i didn't find it even in the documentation (even tough it says "
    Size of the item can be set via the setSize() method or via direct manipulation of the items transformation matrix.", in http://doc.trolltech.com/4.2/qgraphicssvgitem.html)

    Mh, actually the ID is the only element in the scene, but it isn't the root itself.
    Changing it to element layer1 (parent of my object) doesn't change anything. Changing it to the svg element - root of the document - don't display anything.

    Anyway, one should be able to select single element by id, so it shouldn't require to knowing things about its parents.

    Thanks

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.