I'm trying to get the MultiPointTouchArea to work correctly inside a QQuickWidget. Consider the following example qml file(MultiPointTouchTest.qml):
import QtQuick 2.0
Rectangle {
width: 360
height: 480
color: touch1.pressed ? "gray" : "black";
MultiPointTouchArea {
anchors.fill: parent
minimumTouchPoints: 1
maximumTouchPoints: 2
enabled: true;
touchPoints: [
TouchPoint { id: touch1; objectName: "touch 1"; },
TouchPoint { id: touch2; objectName: "touch 2"; }
]
onGestureStarted: {
gesture.grab();
}
onPressed: {
console.log("---onPressed---");
console.log(touch1.objectName, "pressed:", touch1.pressed, touch1.x, touch1.y);
console.log(touch2.objectName, "pressed:", touch2.pressed, touch2.x, touch2.y);
}
onUpdated: {
console.log("---onUpdated---");
console.log(touch1.objectName, "pressed:", touch1.pressed, touch1.x, touch1.y);
console.log(touch2.objectName, "pressed:", touch2.pressed, touch2.x, touch2.y);
}
onReleased: {
console.log("---onReleased---");
console.log(touch1.objectName, "pressed:", touch1.pressed, touch1.x, touch1.y);
console.log(touch2.objectName, "pressed:", touch2.pressed, touch2.x, touch2.y);
}
onTouchUpdated: {
console.log("---onTouchUpdated---");
console.log(touch1.objectName, "pressed:", touch1.pressed, touch1.x, touch1.y);
console.log(touch2.objectName, "pressed:", touch2.pressed, touch2.x, touch2.y);
}
onCanceled: {
console.log("---onCanceled---");
console.log(touch1.objectName, "pressed:", touch1.pressed, touch1.x, touch1.y);
console.log(touch2.objectName, "pressed:", touch2.pressed, touch2.x, touch2.y);
}
}
}
In the main.cpp file, here I use QQuickWidget or QQuickView, like this:
QQuickWidget* quickWidget = new QQuickWidget(QUrl("qrc:///QML/qml/MultiPointTouchTest.qml"));
if (quickWidget->status() == QQuickWidget::Ready) {
QQuickItem* quickItem = quickWidget->rootObject();
quickItem->setProperty("width", QApplication::desktop()->width());
quickItem->setProperty("height", QApplication::desktop()->height());
quickWidget->resize(QApplication::desktop()->width(), QApplication::desktop()->height());
}
or
QQuickView* quickView = new QQuickView(QUrl("qrc:///QML/qml/MultiPointTouchTest.qml"));
... // like QQuickWidget's code
The MultiPointTouchArea's print is different info, for follow sequence operation:
- put my first finger to touch screen
- put my second finger to touch screen; the first finger touch becomes invalid, unimportant for now.
- remove my second finger; the console prints ---onCanceled---..., first finger touch is still invalid and touch1.pressed is false.
Using QQuickView this strange behaviour does not occur.
The Qt's document said for canceled signal, "This signal is emitted when new touch events have been canceled because another item stole the touch event handling."
I don't know document's mean after searched.
I try to read the source code to understand what the happen when I touch screen, but I fond QQuickWidget::event() send touch event(TouchBegin...) to QQuickWindow, and QQuickView::event = QQuickWindow, didn't reimplement.
So, what is real mean for the Qt's document?
I need QQuickWidget not QQuickView so, how can I use MultiPointTouchArea with QQuickWidget and have the correct expected behaviour?
I had a similar issue and found that setting
resolved it.