fingerPaint App - QTouchEvent example
I am trying to modify the fingerPaint app that comes with the MultiTouch example of the SDK, so that it does not display the whole history of events and avoid making it a solid line.
Instead I am using Qt::NoBrush with drawEllipse so that only finger points are painted. But again, I do not want the history displayed. If I am using 5 fingers, I just want 5 rings moving around in the window.
To try this, I have been using the QPainter::eraseRect method with the rect corresponding to the QPoint touchPoint.lastPos(), before painting the current touchPoint. I am doing this in the TouchPointMoved case, so the previous rect is erased.
This is leaving a lot of residue and not very accurate. There’s got to be a better way for this, right?
I am 1 day old with QT, so please bear if this question does not make sense.
Some ideas you could try:
- If using eraseRect(), make sure when update() is called in the foreach loop, it includes the areas where you’ve called erase as well as the new areas you’ve painted.
- If using eraseRect(), make the area you erase slightly larger (like in update(), where adjusted() is called).
- Alternatively, don’t use eraseRect(), and just clear the whole image before painting the touch points, e.g. before the foreach loop, add
- image.fill(qRgb(255, 255, 255));
not sure eraseRect can help here, you will have to repaint that rect from the original image, there may be accuracy issue as tskd has already tried
clearing whole image and repainting will work, but not sure if there will be flicker.
another approach that can be tried is to use a qgraphicsview, and graphics items are created at touch points and these items are moved around instead of painting on original image
Thanks Michael and Chetan.
True, I had tried clearing the screen earlier before each event and there was a lot of flicker and lag.
The qgraphicsview approach seemed to work best. A colleague who is really good at this demonstrated it today incidentally and it seemed to work great. I am yet to try it on more than one touch point.
Thanks for your informed answers!