Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]How to call userdefined function from StyleSheet?
QtWS25 Last Chance

[Solved]How to call userdefined function from StyleSheet?

Scheduled Pinned Locked Moved General and Desktop
10 Posts 4 Posters 4.1k Views
  • 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 Offline
    C Offline
    Charles.qt
    wrote on last edited by
    #1

    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
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      [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
      0
      • C Offline
        C Offline
        Charles.qt
        wrote on last edited by
        #3

        Thank You, Andre for your reply.

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

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #5

            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
            0
            • C Offline
              C Offline
              Charles.qt
              wrote on last edited by
              #6

              Thank you Andre.

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Charles.qt
                wrote on last edited by
                #7

                Thank you Lukas for your suggestion.

                1 Reply Last reply
                0
                • W Offline
                  W Offline
                  walteste
                  wrote on last edited by
                  #8

                  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
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #9

                    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
                    0
                    • W Offline
                      W Offline
                      walteste
                      wrote on last edited by
                      #10

                      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
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved