September 1, 2010

tskd tskd
Lab Rat
1 posts

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.

Thanks

6 replies

September 1, 2010

Deleted Member # 4a2 Deleted Member # 4a2
Ant Farmer
1274 posts

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

September 2, 2010

mbrasser mbrasser
Lab Rat
452 posts

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
    1. image.fill(qRgb(255, 255, 255));

Michael

September 2, 2010

Deleted Member # 4a2 Deleted Member # 4a2
Ant Farmer
1274 posts

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

September 2, 2010

tskd tskd
Lab Rat
1 posts

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!

September 2, 2010

Deleted Member # 4a2 Deleted Member # 4a2
Ant Farmer
1274 posts

glad it worked :)

September 6, 2010

mbrasser mbrasser
Lab Rat
452 posts
chetankjain wrote:
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

Right, good point. I was assuming the image was just a plain white fill. Thanks for the clarification.

Michael

 
  ‹‹ [Solved] QdeclarativeImageprovider issues      [Solved] C++ Signals for QML Layer ››

You must log in to post a reply. Not a member yet? Register here!