[Qt-qml] How to simulate mouse event
martin.jones at nokia.com
martin.jones at nokia.com
Tue Dec 14 00:58:28 CET 2010
We do this in the MouseArea autotests:
QGraphicsScene *scene = canvas->scene();
QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress);
pressEvent.setScenePos(QPointF(100, 100));
pressEvent.setButton(Qt::LeftButton);
pressEvent.setButtons(Qt::LeftButton);
QApplication::sendEvent(scene, &pressEvent);
Keep in mind that the position set above is in scene coordinates.
BR,
Martin.
From: qt-qml-bounces at trolltech.com [mailto:qt-qml-bounces at trolltech.com] On Behalf Of Wangbing Kevin (Nokia-MS/Beijing)
Sent: Monday, 13 December 2010 7:46 PM
To: qt-qml at trolltech.com
Subject: [Qt-qml] How to simulate mouse event
Hi,
I'm a freshman on qml plug-in development.
I want to simulate key and mouse events for testing my qml script automatically.
Now, I can simulate the key event successfully by "item->scene()->sendEvent(item, &keyEvent);"
But it cannot work when I call "item->scene()->sendEvent(item, &mouseEvent);" to simulate mouse event.
I've tried another way "QApplication::sendEvent(view, &mouseEvent);", but it still cannot work.
The return value is always false.
My qml script is follow, it can output log when I click actual mouse key.
Rectangle {
id: container
......
MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: {
mouse.accepted = true;
console.log("Mouse Clicked! key: " + mouse.button + " | keys: " + mouse.buttons);
}
}
Do you have any suggestion?
Best Regards,
Kevin Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20101214/6ed78bc1/attachment.html
More information about the Qt-qml
mailing list