Finding the cordinates in html page using qt
-
Hi,
I am trying to give mouse events over network to a qt browser. In browser i have a socket receving the events .I get a coordinate to click with. I am posting the event to the webpage using
QApplication::sendEvent( view, &releaseEvent );
My Problem is
I need to know the coordinates of icons anad images in html webpage to correctly click on that.
How can I correctly get the cordinates of icons and all in html webpage be known from qt side. -
QWebElement has a geometry() method which returns the geometry inside it's parent frame.
You need to handle and amp the rect upwards until you reach the mainFrame. QWebFrame also provides such a method.
Will probably bit of a pain doing this.Maybe it's way easier to "simulate":http://stackoverflow.com/a/6158050 a mouse click event inside javascript directly.
If your current design is based on QWebElement API thats not a problem. Since the "QtWebkit-Bridging":http://qt-project.org/doc/qt-4.8/qtwebkit-bridge.html takes care of converting a QWebElement object to a Javascript-DOMNode implicitly.
E.g. you can send a signal from Qt - with the QWebElement as an parameter - and catch the signal in javascript.
-
[quote author="raven-worx" date="1389796344"]QWebElement has a geometry() method which returns the geometry inside it's parent frame.
You need to handle and amp the rect upwards until you reach the mainFrame. QWebFrame also provides such a method.
Will probably bit of a pain doing this.Maybe it's way easier to "simulate":http://stackoverflow.com/a/6158050 a mouse click event inside javascript directly.
If your current design is based on QWebElement API thats not a problem. Since the "QtWebkit-Bridging":http://qt-project.org/doc/qt-4.8/qtwebkit-bridge.html takes care of converting a QWebElement object to a Javascript-DOMNode implicitly.
E.g. you can send a signal from Qt - with the QWebElement as an parameter - and catch the signal in javascript.[/quote]
Are you talking about catching the signal in the JavaScript of the "web page" in question? If you can add your own JavaScript to some arbitrary web page (e.g. bankofamerica.com) through the Qt browser, then you can easily set up a communication channel assuming the Qt web stuff allows you to connect to a domain other than the page's domain (e.g. your server instead of bankofamerica.com).
That possible?
-
Rather than catching from html javascript,my objective is to click an image in html page from qtbrowser itself.For that I need to get the coordinates of the image in the html page.Is there any method to find the coordinates of the image in the webpage to click on it. How can i get the coordinates of the elements in webpage from qt side?
I will try with QWebElement -
[quote author="sarahjohn" date="1389849755"]Rather than catching from html javascript,my objective is to click an image in html page from qtbrowser itself.[/quote]
yes a click is more or less a mouse-press event right? So how do you react on mouse clicks anyway on your image elements? This done anyway on HTML/JavaScript right?[quote author="trusktr" date="1389816796"]
Are you talking about catching the signal in the JavaScript of the "web page" in question? If you can add your own JavaScript to some arbitrary web page (e.g. bankofamerica.com) through the Qt browser, then you can easily set up a communication channel assuming the Qt web stuff allows you to connect to a domain other than the page's domain (e.g. your server instead of bankofamerica.com).[/quote]
You can inject your Qt stuff into the loaded webpage's HTML. Thus making your Qt object available in the javascript enginge. This happens after the page has loaded.
I don't know what you meant by connection to another channel? -
as i already said:
handle your way upwards with QWebElement/QWebFrame API
simulate a javascript mouse event on the image element
-
thank you raven-worx.It worked as you said.