[Qt-interest] Line joints overlapping with semi-transparent colour

Samuel Rødal sroedal at trolltech.com
Tue Mar 31 12:25:10 CEST 2009


Andrea Franceschini wrote:
> Hi everybody, I'm facing this problem:
> http://img24.imageshack.us/img24/7389/alphawrong.png
> I think it should be quite clear what's happening: I have a
> semi-transparent pen and I draw subsequent segments using
> QPainter::drawLine(). Obviously at the joints I have that overlapping
> which sums up alpha and results in what you see.
> 
> I have two solutions:
> 1. discard transparency: feasible but ugly;
> 2. use an opaque color which is a mix between a certain degree of pen
> colour and background colour: unfeasible because the background
> changes all the time and in the future I might be interested in
> showing background areas of different colours and even images.
> Moreover I'd like to see what's below the trace (in case there's some
> widget, for example).
> 
> Am I (as usual) missing some piece of the docs?
> 

You could either use QPainter::drawPolyline() which will use the join 
style specified by the currently set pen, or you could draw using a 
fully opaque pen to a transparent pixmap / image, and then draw the 
pixmap / image with a certain opacity set on the painter.

Cheers,
Samuel



More information about the Qt-interest-old mailing list