c++ - Simulating a mouse button press on Qt 5.3 only works the first time -
i've written @ qt5/qml application wish able control remotely web browser. i'm sending screen shot out browser , receiving position x,y in return. i've written c++ class this.
when start application, image comes , first click browser works. second not work. if click anywhere in application, see button press happen on screen, , remote press work 1 more time. suspect problem focus changes , it's not being reset until click on actual application.
i'm using qguiapplicatiop , far haven't been able anythong useful out of itemat or widgetat can send event appropriate object.
here's code snippet show i'm doing.
void wremote::mclick(int x, int y ) { qpointf *pos = new qpointf((qreal)x,(qreal)y); qwindowlist wl = qguiapplication::allwindows(); _mwindow = wl[0]; qmouseevent pevent(qevent::mousebuttonpress, *pos, qt::leftbutton ,qt::leftbutton, 0); qmouseevent revent(qevent::mousebuttonrelease, *pos, qt::leftbutton ,qt::leftbutton, 0); qapplication::instance() ->sendevent(_mwindow, &pevent); qapplication::processevents(); qapplication::instance() ->sendevent(_mwindow, &revent); qapplication::processevents(); }
this first foray integrating qt c++. bulk of application uses pyotherside.
any pointers i'm going wrong appreciated.
thanks,
steve
here's working solution if not elegant one.
void wremote::mclick(int x, int y ) { qtest::mouseclick(_mwindow,qt::leftbutton,0,qpoint(x,y),-1); }
Comments
Post a Comment