首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Qt QGraphicsSvgItem渲染过大(每边0.5个单位)

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

Stack Overflow用户
提问于 2011-09-25 18:24:17
回答 1查看 871关注 0票数 0

如果我在64x64的(0,0)处绘制SVG项,则实际显示的SVG项来自于65x65的(-0.5,-0.5)。我通过在SVG项目后面绘制边界框来测量这一点。并且SVG项目在QGraphicsScene上以半个单位从四边伸出。

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

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

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-09-28 19:39:09

使用transform找到了解决方案:

代码语言:javascript
复制
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));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7544921

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档