[Interest] How to handle Touch Input on C++ side when extending QQuickItem
Alexandru Croitor
alexandru.croitor at qt.io
Thu Apr 20 11:31:17 CEST 2017
So I found out about this recently as well, but touch events are not sent to QQuickItems on macOS by default, because QNativeGestures are sent instead, due to receiving high-precision gestures from the OS itself.
To receive touch events you need to use private API at the moment. Have a look at the implementation of
void QQuickMultiPointTouchArea::setTouchEventsEnabled(bool enable)
You would need to get the relevant function pointer and call registerTouchWindow on your custom QQuickItem.
On 20 Apr 2017, at 10:59, Nuno Santos <nunosantos at imaginando.pt<mailto:nunosantos at imaginando.pt>> wrote:
Alexandru,
Mac OSX, testing with trackpad and mouse.
Regards,
Nuno
On 20 Apr 2017, at 09:36, Alexandru Croitor <alexandru.croitor at qt.io<mailto:alexandru.croitor at qt.io>> wrote:
Hi.
What platform are you testing on?
On 20 Apr 2017, at 10:26, Nuno Santos <nunosantos at imaginando.pt<mailto:nunosantos at imaginando.pt>> wrote:
Hi,
I would like to understand how can I handle a QQuickItem touch input when extending QQuickItem and creating my own item in C++
I can’t find documentation that explains this, neither examples. I have tried the following and none have worked.
What am I missing?
// Implementation
MyItem::MyItem(QQuickItem* parent) :
QQuickItem(parent)
{
setAcceptedMouseButtons(Qt::LeftButton);
setFiltersChildMouseEvents(true);
setKeepTouchGrab(true);
}
// Header
protected:
void mousePressEvent(QMouseEvent *event) {
QQuickItem::mousePressEvent(event);
qDebug() << "mousePressEvent" << event->pos();
}
void mouseMoveEvent(QMouseEvent *event) {
QQuickItem::mouseMoveEvent(event);
qDebug() << "mouseMoveEvent" << event->pos();
}
void mouseReleaseEvent(QMouseEvent *event) {
QQuickItem::mouseReleaseEvent(event);
qDebug() << "mouseReleaseEvent" << event->pos();
}
void mouseReleaseEvent();
void touchEvent(QTouchEvent* event) {
qDebug() << "touch event" << event;
}
bool eventFilter(QObject *, QEvent *event)
{
qDebug() << "processing TouchUpdate...";
if (event->type() == QEvent::TouchUpdate) {
}
// other Touch events here...
return false;
}
Thanks,
Regards,
Nuno
_______________________________________________
Interest mailing list
Interest at qt-project.org<mailto:Interest at qt-project.org>
http://lists.qt-project.org/mailman/listinfo/interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170420/aafa1b41/attachment.html>
More information about the Interest
mailing list