[Solved]How to call userdefined function from StyleSheet?
-
I want to call my function from Stylesheet attribute .
@QPushButton{
background-image:url(:/Image/atom.png);
@getUrl() is my function .
@QPushButton{
background-image: getUrl(url(:/Image/atom.png));
@Please give your suggestions
-
Thank You, Andre for your reply.
Is there any other possiblities to call my function from Stylesheet attribute?
-
A (common) workaround for this is using placeholders in your stylesheet and then pre-processing it.
@
background-image: url(<backgroundImageUrl>);QString styleSheet = ...;
styleSheet.replace("<backgroundImageUrl>", getUrl(...));
styleSheet.replace(...);
@
Brain to terminal. -
Thank you Andre.
-
Thank you Lukas for your suggestion.
-
Another question from my side:
Let's assume i have a button icon, which i assign to the button (stylesheet) like this:
@image: url(:/Image/atom.png);@for the hover state of the button, i would like to use the same image, but manipulate it myself like this:
@image: ApplyOuterGlow(url(:/Image/atom.png));@in which the function would add some glowing effect to the image. That would reduce a lot of work to supply hundreds of hover images.
Is this also not possible?
-
What I do, is using multiple images. I use a separate image for the border, and a transparent image with the icon on top of that. That limits the number of images I need considerably. I only need one common set of base images: normal, disabled, checked/active, normal & hovered, checked & hovered, and one icon image per button.
Again: you can not call functions like you try to do in your example. You're thinking of style sheets in completely the wrong way. They are not like an imparative language, but like a declarative language.