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. Add a Glow effect to QPainter
Forum Updated to NodeBB v4.3 + New Features

Add a Glow effect to QPainter

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 1.7k Views 2 Watching
  • 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.
  • S Offline
    S Offline
    saeid0034
    wrote on last edited by
    #1

    Hi, Im using QPainter to draw some shapes, its all ok but one thing that I want is being able to add a kind of glow effect to my QPainter drawing.
    it is possible?
    I found this post that I think I can use it in some way, but I dont think its the right way (btw sorry for small and not detailed question, I dont know how can I describe it better)

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

      Hi
      The link talks about adding a drop shadow to text so not sure it applies to the effect you want.

      What kind of glow effect ?

      Maybe you can reuse the code from here
      https://forum.qt.io/topic/126659/how-to-draw-a-border-around-a-pixmap-derived-from-png/12

      https://bitbucket.org/kshegunov/dilate/src/master/

      Credits to @kshegunov

      It can draw an outline around a shape and you might be able to tweak it to look like the glow effect you want using more white colors.

      S 1 Reply Last reply
      2
      • mrjjM mrjj

        Hi
        The link talks about adding a drop shadow to text so not sure it applies to the effect you want.

        What kind of glow effect ?

        Maybe you can reuse the code from here
        https://forum.qt.io/topic/126659/how-to-draw-a-border-around-a-pixmap-derived-from-png/12

        https://bitbucket.org/kshegunov/dilate/src/master/

        Credits to @kshegunov

        It can draw an outline around a shape and you might be able to tweak it to look like the glow effect you want using more white colors.

        S Offline
        S Offline
        saeid0034
        wrote on last edited by
        #3

        @mrjj yes the code I mentioned was to add drop shadow but I think it was possible to with some changes get it to work
        by glow I mean something like this
        9df2029a-1e8d-4307-becd-2152a17ab666-image.png
        I dont something exactly like this, just a little glow beside of my shape I draw with QPainter

        pen.setColor(QColor(this->shape_color));
        paint.setPen(pen);
        paint.drawArc(margin, margin, width, height, -90 * 16, -value * 16);
        

        also I tested the code you shared, but I dont think I can use it in my case, because Im not drawing a image

        mrjjM 1 Reply Last reply
        0
        • S saeid0034

          @mrjj yes the code I mentioned was to add drop shadow but I think it was possible to with some changes get it to work
          by glow I mean something like this
          9df2029a-1e8d-4307-becd-2152a17ab666-image.png
          I dont something exactly like this, just a little glow beside of my shape I draw with QPainter

          pen.setColor(QColor(this->shape_color));
          paint.setPen(pen);
          paint.drawArc(margin, margin, width, height, -90 * 16, -value * 16);
          

          also I tested the code you shared, but I dont think I can use it in my case, because Im not drawing a image

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

          @saeid0034

          Hi well yes the code uses QImage as the effect access the pixels directly so I can see that is an issue as even if we render the Widget to a QImage
          the code will apply the effect to all stuff draw not just a signal Shape.

          I was wondering if could cheat some other way.

          How big are the "Shapes" ?

          Maybe we could use a semi-transparent PNG with some gradient on and draw that on top?

          can you show example of a shape ?

          S 1 Reply Last reply
          1
          • mrjjM mrjj

            @saeid0034

            Hi well yes the code uses QImage as the effect access the pixels directly so I can see that is an issue as even if we render the Widget to a QImage
            the code will apply the effect to all stuff draw not just a signal Shape.

            I was wondering if could cheat some other way.

            How big are the "Shapes" ?

            Maybe we could use a semi-transparent PNG with some gradient on and draw that on top?

            can you show example of a shape ?

            S Offline
            S Offline
            saeid0034
            wrote on last edited by
            #5

            @mrjj
            sadly I can't use an static image, because Im drawing and updating the shape in paintEvent, so I need to be able to add the effect in real time to it
            ad8ed867-65c8-4787-9157-161512ce9388-image.png

            kshegunovK 1 Reply Last reply
            0
            • JoeCFDJ Offline
              JoeCFDJ Offline
              JoeCFD
              wrote on last edited by
              #6

              Then use OpenGL to do it.

              1 Reply Last reply
              0
              • S saeid0034

                @mrjj
                sadly I can't use an static image, because Im drawing and updating the shape in paintEvent, so I need to be able to add the effect in real time to it
                ad8ed867-65c8-4787-9157-161512ce9388-image.png

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by
                #7

                @saeid0034 said in Add a Glow effect to QPainter:

                sadly I can't use an static image, because Im drawing and updating the shape in paintEvent, so I need to be able to add the effect in real time to it

                This is actually somewhat simpler, underpaint a slightly blurred version of the ring with a tad larger width and you have the effect. Also, since the whole progress bar (or w/e this is exactly) is actually fixed, you can pre-prepare the image and mask only the bits that you want to be opaque instead.

                Read and abide by the Qt Code of Conduct

                1 Reply Last reply
                3

                • Login

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