PDA

View Full Version : Border cutting with QGraphicsSvgItem



akiross
15th May 2007, 00:12
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:


#include <QApplication>
#include <QSvgRenderer>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsSvgItem>
#include <QBrush>

int main(int argc, char **argv) {
QApplication app(argc, argv);
// Create a renderer for this svg file
QSvgRenderer *svgRend = new QSvgRenderer(QLatin1String("test.svg"));
// Create a scene where set things
QGraphicsScene scene;
// Use a custom brush for the background
QBrush bgBrush(QColor(32, 32, 32), Qt::SolidPattern);
scene.setBackgroundBrush(bgBrush);
// Create svg item for the scene
QGraphicsSvgItem *svg = new QGraphicsSvgItem();
svg->setSharedRenderer(svgRend);
svg->setElementId(QLatin1String("shape"));
// Add the item to the scene
scene.addItem(svg);
// Initialize the view
QGraphicsView view(&scene);
view.show();
return app.exec();
}

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

svg->rotate(5.0);
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 :)

marcel
15th May 2007, 08:50
How about if you resize the item with QGraphicsItem::setSize() ?
Is the ID passed to setElementId the root SVG element?

akiross
15th May 2007, 09:12
:confused: 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 :)