Qt QGraphicsSvgItem渲染太大(每边0.5个单位)

时间:2011-09-25 10:24:17

标签: qt svg bounding-box qgraphicsscene

如果我使用64x64在(0,0)处绘制SVG项目,则实际显示的SVG项目来自(-0.5,-0.5)65x65。我通过绘制SVG项目后面的边界框来测量它。并且QG项目在QGraphicsScene的半个单元四周伸出。

我可以删除此效果吗?我把笔设置为NoPen。 我可以缩小它,但这将是非常不准确的(因为宽度和高度需要不同的缩放,这几乎是不可能的)。我该如何解决这个问题?

enter image description here

如您所见,棕色框(SVG)伸出灰色区域(边界框)。使用Inkscape确认边界框。

由于

1 个答案:

答案 0 :(得分:0)

使用transform找到解决方案:

QSvgRenderer *test = new QSvgRenderer(QLatin1String("test.svg"));

QGraphicsSvgItem *item = new QGraphicsSvgItem();
item->setSharedRenderer(test);
addItem(item);

// the following transformation is required if you want the SVG to be exactly on the spot and as big as it should be
item->setTransform(QTransform(test->viewBoxF().width() / (test->viewBoxF().width() + 1.0), 0.0, 0.0, test->viewBoxF().height() / (test->viewBoxF().height() + 1.0), 0.5, 0.5));