QSvgRenderer using an external CSS file
-
The SVG support in Qt meets a subset of SVG Tiny specification. SVG Tiny only supports a subset of CSS styling and also states, "Authors must not rely on external, author stylesheets to style documents that are intended to be used with SVG Tiny 1.2 user agents."
What are you trying to achieve, and what exactly is failing?
-
As to what is failing, I just have a simple SVG image in which I am trying to override the color used for the stoke color. I have tried many things, and I can not get anything to work from the CSS.
That is why I was asking for a very simple example of getting CSS to work from SVG.
-
Thank you all. I was able to figure out how to do this. I guess part of my problem is not understanding that when using a CSS with an SVG, the styling in the CSS will not override the values for the SVG element, just use it if it was not defined.
For example, if you have a 'path' element, and there is already a stroke color defined as in:
<path stroke="yellow" stroke-width="6" d="M 100,60 140,30 150,50 160,30 170,80" />
The following CSS value will not replace "yellow" with "red"
path {
stroke: red;
} -
@KSierens
But that is true for all CSS on any HTML element: any property set explicitly on any element overrides any rule in CSS, which is only used for defaults if nothing explicitly, and always has been like that.Full CSS in HTML allows you to use the
!important
directive in a CSS rule (stroke: red !important;
) and that would actually override even matching style explicitly placed on an element. But Qt's CSS is a subset of full CSS and does not support!important
, so you can't do that.