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. Stylesheet: background-image size relative to widget while keeping aspect ratio

Stylesheet: background-image size relative to widget while keeping aspect ratio

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 3 Posters 10.0k 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.
  • Q Offline
    Q Offline
    qwasder85
    wrote on 6 Feb 2018, 14:26 last edited by qwasder85 2 Jun 2018, 14:27
    #1

    I would like my QGroupBoxes to feature a watermark in their bottom-left that is a certain percentage of the QGroupBox's width and keeps its 1:1 aspect ratio.

    This is the effect I want to achieve:
    alt text

    Here is my stylesheet:

    QGroupBox#simpleGroupBox
    {
        border: 1px solid #cccccc;
        background-image: url(:/Images/watermark.png);
        background-position: bottom left;
        background-repeat: no-repeat;
    }
    

    Can this be done with stylesheets alone?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 6 Feb 2018, 15:13 last edited by
      #2

      Hi
      Seems to work fine ?
      Do you get other result ?
      alt text

      Q 1 Reply Last reply 7 Feb 2018, 09:37
      0
      • M mrjj
        6 Feb 2018, 15:13

        Hi
        Seems to work fine ?
        Do you get other result ?
        alt text

        Q Offline
        Q Offline
        qwasder85
        wrote on 7 Feb 2018, 09:37 last edited by
        #3

        @mrjj It doesn't work with a large image that needs to be scaled down to the group box size, and it also doesn't scale when I resize the window.

        M 1 Reply Last reply 7 Feb 2018, 09:45
        0
        • Q qwasder85
          7 Feb 2018, 09:37

          @mrjj It doesn't work with a large image that needs to be scaled down to the group box size, and it also doesn't scale when I resize the window.

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 7 Feb 2018, 09:45 last edited by
          #4

          @qwasder85
          Ah, sorry, i completely missed the scaling part.
          As far as i know, scaling is not possible with background-image
          but some seems to have used border-image instead
          https://forum.qt.io/topic/40151/solved-scaled-background-image-using-stylesheet

          J Q 2 Replies Last reply 7 Feb 2018, 10:36
          0
          • M mrjj
            7 Feb 2018, 09:45

            @qwasder85
            Ah, sorry, i completely missed the scaling part.
            As far as i know, scaling is not possible with background-image
            but some seems to have used border-image instead
            https://forum.qt.io/topic/40151/solved-scaled-background-image-using-stylesheet

            J Offline
            J Offline
            JonB
            wrote on 7 Feb 2018, 10:36 last edited by
            #5

            @mrjj, @qwasder85

            HTML CSS has background-size (e.g. https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Backgrounds_and_Borders/Scaling_background_images, https://stackoverflow.com/questions/1150163/stretch-and-scale-a-css-image-in-the-background-with-css-only). Does this exist/work in QSS?

            Q 1 Reply Last reply 7 Feb 2018, 10:49
            0
            • J JonB
              7 Feb 2018, 10:36

              @mrjj, @qwasder85

              HTML CSS has background-size (e.g. https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Backgrounds_and_Borders/Scaling_background_images, https://stackoverflow.com/questions/1150163/stretch-and-scale-a-css-image-in-the-background-with-css-only). Does this exist/work in QSS?

              Q Offline
              Q Offline
              qwasder85
              wrote on 7 Feb 2018, 10:49 last edited by
              #6

              @JonB I think this does exist, but what would I set it to?

              J 1 Reply Last reply 7 Feb 2018, 10:55
              0
              • M mrjj
                7 Feb 2018, 09:45

                @qwasder85
                Ah, sorry, i completely missed the scaling part.
                As far as i know, scaling is not possible with background-image
                but some seems to have used border-image instead
                https://forum.qt.io/topic/40151/solved-scaled-background-image-using-stylesheet

                Q Offline
                Q Offline
                qwasder85
                wrote on 7 Feb 2018, 10:53 last edited by
                #7

                @mrjj Your linked thread seems to be the exact same issue. Thanks.
                Doesn't seem clear whether or not it is actually possible with stylesheets only (which is what I would prefer). I'll try experimenting with border-image.

                1 Reply Last reply
                0
                • Q qwasder85
                  7 Feb 2018, 10:49

                  @JonB I think this does exist, but what would I set it to?

                  J Offline
                  J Offline
                  JonB
                  wrote on 7 Feb 2018, 10:55 last edited by
                  #8

                  @qwasder85
                  Presumably (assuming it works) you would need to get the container (GroupBox) size in code, and then do an explicit setStylesheet() call?

                  Q 1 Reply Last reply 7 Feb 2018, 10:58
                  0
                  • J JonB
                    7 Feb 2018, 10:55

                    @qwasder85
                    Presumably (assuming it works) you would need to get the container (GroupBox) size in code, and then do an explicit setStylesheet() call?

                    Q Offline
                    Q Offline
                    qwasder85
                    wrote on 7 Feb 2018, 10:58 last edited by qwasder85 2 Jul 2018, 10:59
                    #9

                    @JonB That would work, though I'm trying to have this background apply to any groupbox used in my application automatically, without me having to touch it. That's why I want to solve this with stylesheets (I'm lazy and try to be efficient). :)
                    If it turns out it's impossible (right now it looks that way), there won't be a watermark, haha. I try to move away from setting dynamic stylesheets in code.

                    J 1 Reply Last reply 7 Feb 2018, 11:15
                    0
                    • Q qwasder85
                      7 Feb 2018, 10:58

                      @JonB That would work, though I'm trying to have this background apply to any groupbox used in my application automatically, without me having to touch it. That's why I want to solve this with stylesheets (I'm lazy and try to be efficient). :)
                      If it turns out it's impossible (right now it looks that way), there won't be a watermark, haha. I try to move away from setting dynamic stylesheets in code.

                      J Offline
                      J Offline
                      JonB
                      wrote on 7 Feb 2018, 11:15 last edited by
                      #10

                      @qwasder85
                      I only know about the HTML/CSS3 size, I'm afraid. https://www.sitepoint.com/css3-background-size-property/ and https://stackoverflow.com/questions/5766825/css-scaled-background-image use background-size: cover OR contain;, but I don't suppose QSS will allow that?

                      Q 1 Reply Last reply 7 Feb 2018, 12:04
                      0
                      • J JonB
                        7 Feb 2018, 11:15

                        @qwasder85
                        I only know about the HTML/CSS3 size, I'm afraid. https://www.sitepoint.com/css3-background-size-property/ and https://stackoverflow.com/questions/5766825/css-scaled-background-image use background-size: cover OR contain;, but I don't suppose QSS will allow that?

                        Q Offline
                        Q Offline
                        qwasder85
                        wrote on 7 Feb 2018, 12:04 last edited by
                        #11

                        @JonB Doesn't look like it. It seems to have no effect.

                        1 Reply Last reply
                        0

                        1/11

                        6 Feb 2018, 14:26

                        • Login

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