[Qt-qml] How to simulate mouse event

kevin.wangbing at nokia.com kevin.wangbing at nokia.com
Tue Dec 14 07:51:54 CET 2010


Hi Martin,

I've done some tests for the mouse event simulation and found a rule:
The mouse release event cannot be sent singly, it must be paired with a mouse press event and a mouse click event will be send by system automatically.
So I cannot send a single mouse release event to any object, it's right?

BR,
Kevin Wang

From: Jones Martin (Nokia-MS-Qt/Brisbane)
Sent: Tuesday, December 14, 2010 1:26 PM
To: Wangbing Kevin (Nokia-MS/Beijing); qt-qml at trolltech.com
Subject: RE: How to simulate mouse event

We handle mouse release in our tests without any problem.  Are you able to provide a runable example?

BR,
Martin.

From: Wangbing Kevin (Nokia-MS/Beijing)
Sent: Tuesday, 14 December 2010 2:19 PM
To: Jones Martin (Nokia-MS-Qt/Brisbane); qt-qml at trolltech.com
Subject: RE: How to simulate mouse event

Hi Martin,

Thanks for your great suggestion!
The most mouse events can be simulated successfully except GraphicsSceneMouseRelease event.
The onReleased handler still cannot be triggered.

What's the matter?
Hope you or others can help me again, thank you!

BR,
Kevin Wang

From: Jones Martin (Nokia-MS-Qt/Brisbane)
Sent: Tuesday, December 14, 2010 7:58 AM
To: Wangbing Kevin (Nokia-MS/Beijing); qt-qml at trolltech.com
Subject: RE: How to simulate mouse event

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/413276d5/attachment.html 


More information about the Qt-qml mailing list