Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    [Solved]How to call userdefined function from StyleSheet?

    General and Desktop
    4
    10
    3704
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      Charles.qt last edited by

      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

      1 Reply Last reply Reply Quote 0
      • A
        andre last edited by

        [quote author="sweeten" date="1342004010"]I want to call my function from Stylesheet attribute .
        [/quote]
        You cannot. Sorry.
        [quote]
        Give your suggestions[/quote]
        Using "please" will get you a long way...

        1 Reply Last reply Reply Quote 0
        • C
          Charles.qt last edited by

          Thank You, Andre for your reply.

          Is there any other possiblities to call my function from Stylesheet attribute?

          1 Reply Last reply Reply Quote 0
          • A
            andre last edited by

            No, style sheets can set properties, but you cannot use values from properties or functions in them.

            1 Reply Last reply Reply Quote 0
            • L
              lgeyer last edited by

              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.

              1 Reply Last reply Reply Quote 0
              • C
                Charles.qt last edited by

                Thank you Andre.

                1 Reply Last reply Reply Quote 0
                • C
                  Charles.qt last edited by

                  Thank you Lukas for your suggestion.

                  1 Reply Last reply Reply Quote 0
                  • W
                    walteste last edited by

                    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?

                    1 Reply Last reply Reply Quote 0
                    • A
                      andre last edited by

                      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.

                      1 Reply Last reply Reply Quote 0
                      • W
                        walteste last edited by

                        Thanks Andre, that makes it more clear for me. So the only approach to add more dynamic is the pre-parsing mechanism.

                        That helps yo understand stylesheets more. Thanks again!

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post