Qt支持在QIcon中为SVG着色 [英] Qt support for coloring SVG in a QIcon

查看:910
本文介绍了Qt支持在QIcon中为SVG着色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Qt似乎不支持SVG中path标记上的描边/填充选项:

It appears that Qt doesn't support the stroke/fill options on the path tag within a SVG:

<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8" viewBox="0 0 8 8">
   <path fill="green" stroke="red" d="M2 0c1 2-2 3-2 5s2 3 2 3c-.98-1.98 2-3 2-5s-2-3-2-3zm3 3c1 2-2 3-2 5h3c.4 0 1-.5 1-2 0-2-2-3-2-3z" />
</svg>

我使用QIcon通过Qt的资源加载器将其加载到我的应用程序中:

I load this into my application via Qt's resource loader, using a QIcon:

QIcon icon(":/svgs/fire.svg");

无论SVG属性如何,它都以白色显示为黑色.当我在Firefox中打开SVG时,颜色会很受尊重. (请注意,我也尝试过使用十六进制值作为颜色参数).

It displays as black on white regardless of the SVG properties. When I open the SVG in Firefox, the colors are honored. (Note, I've also tried hex values for the color arguments).

我在俯视什么吗?有没有其他方法可以在Qt中为SVG/QIcons着色?

Am I overlooking something? Is there another way to color SVGs/QIcons in Qt?

推荐答案

我有一个类似的问题,但来自Qt的另一部分.我正在使用QAction在QToolBar上创建一个按钮.当我将QAction的图标设置为SVG资源时,最终会得到像素化图像.

I am having a similar issue but from another part of Qt.. i am using a QAction to create a button on QToolBar. When i set the icon of the QAction to an SVG resource, i end up with a pixelated image.

我正在运行视网膜显示计算机,尝试缩放我的svg坐标并更改我的显示dpi,但两者均不起作用.

I am running a retina display machine, tried both scaling up my svg co-ordinates, and changing my display dpi, but both do not work.

我得出的结论是,Qt将矢量图像隐式转换为QToolBar QAction图标的光栅图像.我不知道这是否对您有帮助,但是我值得一提.

I came to the conclusion that Qt implicitly transforms the vector image to a raster image for QToolBar QAction icons. I don't know if this help you or not, but i though it's worth mentioning.

这篇关于Qt支持在QIcon中为SVG着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆