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. Animated gif inside QLabel not be drawn transparently
QtWS25 Last Chance

Animated gif inside QLabel not be drawn transparently

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 2.6k 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.
  • T Offline
    T Offline
    Taytoo
    wrote on last edited by
    #1

    I have a QWidget 'A' with a background-image set in its stylesheet - nothing else is drawn on it. On top of the QWidget I have a QLabel widget (children of the 'A') with background set to Transparent. I'm playing an animated gif inside this QLabel using QMovie, the gif itself has transparency (spinner effect).

    When I run the application it looks like the spinner is continuously being drawn on itself without background of the parent being re-drawn first? Then I just tried displaying a text in the Label, but even with just text, the background of the parent is Not being drawn. How do I fix these issues?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      Make sure your stylesheet doesn't also affect the Label by using
      too broad selector.

      QWidget#centralWidget {
      background-image: url(:/garden.jpg);
      }

      Works fine for fast test.
      alt text

      S 1 Reply Last reply
      3
      • T Offline
        T Offline
        Taytoo
        wrote on last edited by
        #3

        I was able to solve the background not drawing issue by painting the jpg manually - I had to do it because I wanted to custom fit the background.

        The issue I'm seeing now are the white areas around the edges, as you see in your gif as well. Looks like the edges are not per-pixel alpha-blended with the background?

        mrjjM 1 Reply Last reply
        0
        • T Taytoo

          I was able to solve the background not drawing issue by painting the jpg manually - I had to do it because I wanted to custom fit the background.

          The issue I'm seeing now are the white areas around the edges, as you see in your gif as well. Looks like the edges are not per-pixel alpha-blended with the background?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @Taytoo
          Nope, its not. Gif cannot do multilevel transparency.

          T 1 Reply Last reply
          0
          • mrjjM mrjj

            @Taytoo
            Nope, its not. Gif cannot do multilevel transparency.

            T Offline
            T Offline
            Taytoo
            wrote on last edited by Taytoo
            #5

            @mrjj Any ideas, how to fix this/workarounds?

            1 Reply Last reply
            0
            • T Offline
              T Offline
              Taytoo
              wrote on last edited by
              #6

              Found this answer on stackoverflow: https://stackoverflow.com/questions/24592918/gif-image-in-qlabel

              Although it was related to Graphics Scene, I tried it out, still no luck :(

              J.HilkJ 1 Reply Last reply
              0
              • T Taytoo

                Found this answer on stackoverflow: https://stackoverflow.com/questions/24592918/gif-image-in-qlabel

                Although it was related to Graphics Scene, I tried it out, still no luck :(

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #7

                @Taytoo you could potentially do it manually.
                Save the gif frames as images, overwrite the paint event and draw one of the images. Set a timer to change the image periodically.


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                1
                • mrjjM mrjj

                  Hi
                  Make sure your stylesheet doesn't also affect the Label by using
                  too broad selector.

                  QWidget#centralWidget {
                  background-image: url(:/garden.jpg);
                  }

                  Works fine for fast test.
                  alt text

                  S Offline
                  S Offline
                  Sakshi053
                  wrote on last edited by
                  #8

                  @mrjj How did you made this gif work i'm also using a gif with transparent background but its not working ?

                  mrjjM 1 Reply Last reply
                  0
                  • S Sakshi053

                    @mrjj How did you made this gif work i'm also using a gif with transparent background but its not working ?

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @Sakshi053
                    Nothing special. JUst using QMovie.
                    Try the test project and see

                    https://www.dropbox.com/s/ebdoleidabqi3ci/stylesheetTest.zip?dl=0

                    1 Reply Last reply
                    1

                    • Login

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