Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. synthetic mouse events in Qt 5.3 QGuiApplication

synthetic mouse events in Qt 5.3 QGuiApplication

Scheduled Pinned Locked Moved QML and Qt Quick
c++qt5qtquick sendeve
2 Posts 1 Posters 849 Views 1 Watching
  • 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.
  • M Offline
    M Offline
    morris200
    wrote on last edited by
    #1

    Hi All,

    I've wtitten a Qt 5.3 QGuiApplication program which uses QtQuick and
    pyotherside for the back end. I'm trying to control the program remotely
    through a web browser.

    I send a screenshot out to the browser and get XY coordinates back, This
    is working for the first button press. It doesn't work after that unless
    I click on the actual display or move the mouse out of the window and back in.

    I've noticed that my program works when mouseGrabber == 0. After the
    first click, this gets set and my program no longer works.

    It appears that I have to do some more event handling somewhere, but
    after a few days of poring over documentation ( much of it appearing to
    be useful but applying to QWidgets or Wt4 ) and trying
    everything I can think of I've decided to ask for help.

    This is my first try at writing C++ for Qt and my second C++ program,
    the first of which I wrote some 30 years ago,

    Here's a code snippet to show what I'm trying to do.

    If someone could point me in the right direction, I would appreciate it.

    Thanks.

    void Wremote::mClick(int x, int y ) {
        QWindowList wl = QGuiApplication::allWindows();
       _mwindow = wl[0];
       QPointF pos((qreal)x,(qreal(y)));
    
    	QMouseEvent pevent(QEvent::MouseButtonPress, pos, Qt::LeftButton
    					  ,Qt::LeftButton, 0);
    
    	QMouseEvent revent(QEvent::MouseButtonRelease, pos, Qt::LeftButton
    					  ,Qt::LeftButton, 0);
    
    	QGuiApplication::sendEvent(_mwindow, &pevent);
    	QGuiApplication::sendEvent(_mwindow, &revent);
    	QGuiApplication::processEvents();
    }
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      morris200
      wrote on last edited by
      #2

      While I never managed to do it this way, I came up with a working solution.

      void Wremote::mClick(int x, int y ) {
          QTest::mouseClick(_mwindow,Qt::LeftButton,0,QPoint(x,y),-1);
      }
      
      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