Add a Glow effect to QPainter
-
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) -
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/12https://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.
-
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/12https://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.
@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
I dont something exactly like this, just a little glow beside of my shape I draw with QPainterpen.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
-
@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
I dont something exactly like this, just a little glow beside of my shape I draw with QPainterpen.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
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 ?
-
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 ?
-
@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
@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.