Simple automated Mouse Click does not work!
-
raven-worx: I have just checked by changing as following. Then as you said, my local & global coordinates will change.
@//viewer.showFullScreen();
viewer.showMaximized();@As my application is running in full-screen, they are same. When I change mouse position using setPos(), mouse is moving to the correct position. So, this means, my perception of clicking position is correct.
Anyone tried to run this code? -
I've added following lines to test the points I have sent relative to global/window/local etc.,
All of them gave same result, as my application is full-screen application. This means coordinates I'm sending to the application are correct irrespective of the window/local/global coordinate positions.@ qDebug() << pressEvent.globalPos().x() << "; " << pressEvent.globalPos().y();
qDebug() << pressEvent.windowPos().x() << "; " << pressEvent.windowPos().y();
qDebug() << pressEvent.screenPos().x() << "; " << pressEvent.screenPos().y();
qDebug() << pressEvent.localPos().x() << "; " << pressEvent.localPos().y();@
The code is here for mouseClick() : http://pastebin.com/bgVXg38iPlease help me!! I have been struggling for this since 3 weeks!! :(
-
sure they are all the same...
@
QMouseEvent pressEvent(QEvent::MouseButtonPress, QPointF(x, y),
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPointF(x, y),
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);qDebug() << pressEvent.globalPos().x() << "; " << pressEvent.globalPos().y(); qDebug() << pressEvent.windowPos().x() << "; " << pressEvent.windowPos().y(); qDebug() << pressEvent.screenPos().x() << "; " << pressEvent.screenPos().y(); qDebug() << pressEvent.localPos().x() << "; " << pressEvent.localPos().y();
@
Just reading this 6 lines of code, how should the event return something useful for windowPos()?! So you have have passed local coordinates - which are relative to "???" - but want the global/window pos?! This can't work.
Please provide a ready to start project so i just need to open it in QtCreator and press "run".
-
I'm sorry. I should have done this ages ago.
"Here is the link for code till now.":https://github.com/inblueswithu/InAppMouse/releases/tag/v0.1I guess I have made a whole mess with that global/local coordinates. I didnt get this in this context.
-
ok have tried it.... seems to work like expected.
But it still has the endless loop in it. Since you trigger your QML signals for both buttons and listen to the signal to trigger it again....Your MouseArea also covers it's whole parent, thus it doesn't matter where you click it always triggers the signal which then leads to the endless recursion.
I guess what you want is 2 MouseArea elements which trigger different signals??
-
Ya. I want 2 mouse area signals which signal differently.
What I did is when I click a mouse area, it should click the adjacent mouse area too. (The one, where the mouse moves, in my code)
My code is moving cursor to that desired location but not clicking in that position. It is clicking repeatedly in the first area only.Please observe console output too when clicked buttons. A console output is given to second column Rectangles also.
Note: Rectangles beside first column rects are also buttons
-
[quote author="raven-worx" date="1385149213"]seems to work like expected. But it still has the endless loop in it. [/quote]
No, It does not work as expected. It is just taking the click ! But not doing a software automated click in correct position, as you have observed.[quote author="raven-worx" date="1385149213"]
Your MouseArea also covers it's whole parent, thus it doesn't matter where you click it always triggers the signal which then leads to the endless recursion.[/quote]
My MouseArea covers the parent Rectangle, That means it only responds only when clicked inside that button. True, it is having endless recursion because somehow the click is happening inside that button though I have provided coordinates to click somewhere else (the button adjacent to it) -
no your mouse area is overlapping actually both buttons!
@
width: parent.width/2
height: parent.height/2
anchors.centerIn: parent
@ -
Sorry, I guess you are seeing main.qml. But I'm using TryMouse.qml
@viewer.setMainQmlFile(QStringLiteral("qml/MouseSimulation/TryMouse.qml"));@Note: I had used main.qml for previous testing.
-
yes you are write i looked at the wrong qml file.
I've debugged into your project. When you apply the following changes it works like intended:
@
//button
Rectangle {
id: button1
width: 100
height: 50
anchors.left: parent.left
anchors.top: parent.top
color: "lightgreen"
border.color: "red"
border.width: 1Text { anchors.centerIn: parent text: "Click Me!" } MouseArea { anchors.fill: parent propagateComposedEvents: true onClicked: { statusText = "button1 pressed" console.log("Mouse button1 press") mouse.accepted = contains(Qt.point(mouse.x, mouse.y)) if( mouse.accepted ) button1pressed(150, 25) } } }
@
So set the propagateComposedEvents to true and only accept the mouse event when it is really inside the mouse area.For some reason the first mouse area always stole the mouse events before the second one. I don't know the exactly reason for that though.
-
Thankyou so much. I cant tell you how happy I'm.
You really deserve a beer.
[quote author="raven-worx" date="1385366800"]For some reason the first mouse area always stole the mouse events before the second one. I don't know the exactly reason for that though.[/quote]
Ya. I have been struggling for this ! I'm thinking of filing a bug.
Click is being recognized as you suggested. But hovering (onEntered/onExited) are not working! Hope there has some workaround for this. -
Have you checked the property
"hoverEnabled":http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-mousearea.html#hoverEnabled-prop ?bq. Qt5 docs
By default, mouse events are only handled in response to a button event, or when a button is pressed. Hover enables handling of all mouse events even when no mouse button is pressed.
This property affects the containsMouse property and the onEntered, onExited and onPositionChanged signals.It gave me similar problems some time ago.
-
[quote author="ariacorrente" date="1385465841"]Have you checked the property
"hoverEnabled":http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-mousearea.html#hoverEnabled-prop ?[/quote]
Ya. I have that. It works before 1st click but then... It dont.