QPainter doesn't draw lines or images
-
I now create a signature capture function using the fingerpaint project in the qt 4.8.5's example.
But the QPainter doesn't draw any line or image.A touch event calls the following event function(bool ScribbleArea::event(QEvent *event)).
But the event type(event->type()) is always default case, not TouchBegin, TouchUpdate or TouchEnd.bool ScribbleArea::event(QEvent *event) { switch (event->type()) { case QEvent::TouchBegin: case QEvent::TouchUpdate: case QEvent::TouchEnd: { QList<QTouchEvent::TouchPoint> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints(); foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints) { switch (touchPoint.state()) { case Qt::TouchPointStationary: // don't do anything if this touch point hasn't moved continue; default: { QRectF rect = touchPoint.rect(); if (rect.isEmpty()) { qreal diameter = qreal(50) * touchPoint.pressure(); rect.setSize(QSizeF(diameter, diameter)); } QPainter painter(&image); painter.setPen(Qt::NoPen); painter.setBrush(myPenColors.at(touchPoint.id() % myPenColors.count())); painter.drawEllipse(rect); painter.end(); modified = true; int rad = 2; update(rect.toRect().adjusted(-rad,-rad, +rad, +rad)); } break; } } break; } default: return QWidget::event(event); } return true; }
Should I set any option to draw a line or image by touching screen?
Thanks
-
Hi,
What event do you get ?
Also, please be aware that 4.8.5 is obsolete since several years so depending on what you want to do, you will have to implement some things yourself.One that note, you should consider to use the latest release of the series if not an actual version of Qt.
-
Dear SGaist,
I have got the mouse event(MouseButtonPress, MouseMove, MouseButtonRelease).
What should I modify to draw a line or image by touching screen?
I want to use the qt 4.8.5 because an old project uses it.(I am a beginner in the qt.)Thanks
-
Since the touch screen triggers the mouse event, just handle the mouse events.
In any case, since you are new to Qt, you really really should start with a recent version of Qt. Qt 4 has reached end of life literally a decade ago.
-