View Full Version : How to implement transparent pencil tool in Qt?

10th June 2012, 07:01
I'm currently making a Painter like program. And I want to implement a painting tool, pencil, can draw in transparent color, such as rgb(255,0,0,100).

I've tried to use QPainter and draw things in a QImage and then draw on a QWidget.

Using QPainter::drawLine with QWidget::mouseMoveEvent is nice when the color is totally opacity one. However, if I use a transparent color, the point that both belongs to the last line and current line, will drawn twice(see attachment).

And I also tried using QPainter:drawPath and QPainter::drawLines, but none of them are right for this. They won't double draw the "last point" between two lines, but can't draw twice even when user intend to do so( saying you're drawing "8" and the cross should be drawn twice).

So, maybe impossible, is there a way to solve this? Implement a basic pencil tool?

12th June 2012, 16:24
Nobody knows?

12th June 2012, 20:08
I certainly don't know for sure, but my guess would be to draw an opaque path in an off-screen buffer, apply alpha correction to it, and then transfer it to the screen.

14th June 2012, 05:16
It works if we only draw once. However, any new painted color can't use opaque color to compose with the old painted colors.