Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Simple automated Mouse Click does not work!
Forum Update on Monday, May 27th 2025

Simple automated Mouse Click does not work!

Scheduled Pinned Locked Moved General and Desktop
21 Posts 3 Posters 8.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    inblueswithu
    wrote on last edited by
    #9

    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?

    1 Reply Last reply
    0
    • I Offline
      I Offline
      inblueswithu
      wrote on last edited by
      #10

      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/bgVXg38i

      Please help me!! I have been struggling for this since 3 weeks!! :(

      1 Reply Last reply
      0
      • raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #11

        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".

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • I Offline
          I Offline
          inblueswithu
          wrote on last edited by
          #12

          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.1

          I guess I have made a whole mess with that global/local coordinates. I didnt get this in this context.

          1 Reply Last reply
          0
          • raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #13

            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??

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • I Offline
              I Offline
              inblueswithu
              wrote on last edited by
              #14

              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

              1 Reply Last reply
              0
              • I Offline
                I Offline
                inblueswithu
                wrote on last edited by
                #15

                [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)

                1 Reply Last reply
                0
                • raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by
                  #16

                  no your mouse area is overlapping actually both buttons!
                  @
                  width: parent.width/2
                  height: parent.height/2
                  anchors.centerIn: parent
                  @

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  0
                  • I Offline
                    I Offline
                    inblueswithu
                    wrote on last edited by
                    #17

                    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.

                    1 Reply Last reply
                    0
                    • raven-worxR Offline
                      raven-worxR Offline
                      raven-worx
                      Moderators
                      wrote on last edited by
                      #18

                      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: 1

                          Text {
                              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.

                      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                      If you have a question please use the forum so others can benefit from the solution in the future

                      1 Reply Last reply
                      0
                      • I Offline
                        I Offline
                        inblueswithu
                        wrote on last edited by
                        #19

                        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.

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          ariacorrente
                          wrote on last edited by
                          #20

                          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.

                          1 Reply Last reply
                          0
                          • I Offline
                            I Offline
                            inblueswithu
                            wrote on last edited by
                            #21

                            [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.

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved