FingerPaint App - QTouchEvent example
-
wrote on 1 Sept 2010, 08:06 last edited by
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.Thanks
-
wrote on 1 Sept 2010, 19:11 last edited by
if u see the code of the fingerpaint app, the painter draws directly on the image on every touch event. the image is permanently modified here ... so u have to work around keeping this in mind
-
wrote on 1 Sept 2010, 23:38 last edited by
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));@
Michael
-
wrote on 2 Sept 2010, 05:38 last edited by
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
-
wrote on 2 Sept 2010, 11:01 last edited by
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!
-
wrote on 2 Sept 2010, 13:03 last edited by
glad it worked :)
-
wrote on 6 Sept 2010, 00:09 last edited by
[quote author="chetankjain" date="1283405899"]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[/quote]
Right, good point. I was assuming the image was just a plain white fill. Thanks for the clarification.
Michael
1/7