PDA

View Full Version : Stippled Pattern when Painting with mouse/tablet



DanqueDynasty
22nd March 2014, 05:48
Hello all,

I am experience a problem where if I try to draw with pen/tablet input, the widget will draw a line along with circles at points periodically. Such as the following:
10158
The code(in context of QTabletEvent, QMouseEvent is coded the same way):



bool deviceDown = false;
QPoint drawPath[3];

void Editor::TabletEvent(QTabletEvent* event)
{
if(event->type() == QEvent::TabletPress)
{
deviceDown = true;
drawPath[2] = drawPath[1] = drawPath[0] = event->pos();
}
if(event->type() == QEvent::TabletRelease)
{
if(deviceDown == true){deviceDown = false;}
}

if(event->type() == QEvent::TabletMove)
{
drawPath[2] = drawPath[1];
drawPath[1] = drawPath[0];
drawPath[0] = event->pos();

/* DRAW CODE - Commented out due to actual code residing in another class/function.
QPainter painter(&pixmap);
painter.drawLine(drawPath[1], event->pos());
*/
}
}


I have attempted to use a single point as the last known point, but that failed. Using a QPoint array seams to be the only way to get the widget to draw any lines correctly.

ChrisW67
24th March 2014, 04:47
You paint a translucent (alpha < 1.0) line from A to B, then B to C, C to D etc. The point B is painted twice, once for each line it is part of. The result is that the brush area on top of point B is now darker. Same goes for C etc.

Options:

Accumulate points from press to release and then draw a single poly-line (QPainter::drawPolyLine())
Accumulate points from press and draw a single polyline onto a transparent overlay image that you then compose with the base image onto the display. When the finger is raised draw the entire polyline into the base image.

DanqueDynasty
29th March 2014, 01:02
Alright I'll try that out. Will the same method work if I invoke "painter.drawPixmap()" or "painter.drawEllipse"?