PDA

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



liuyanghejerry
10th June 2012, 06: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?

liuyanghejerry
12th June 2012, 15:24
Nobody knows?

kuroi_neko
12th June 2012, 19: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.

liuyanghejerry
14th June 2012, 04: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.