PDA

View Full Version : QWebkit and dragging problem



.:saeed:.
25th August 2012, 14:17
As you may know google maps ,see here (https://google-developers.appspot.com/maps/documentation/javascript/examples/map-simple), are drag-able . I saved this example (https://google-developers.appspot.com/maps/documentation/javascript/examples/map-simple) from google developers and loaded it in a QWebView object. The map itself loads successfully but I have no dragging, no double clicking and no other mouse events. That would be a bug if I'm true. I want to write a program that shows a map to users in a touch-enabled device . So my program needs to be able to be flicked with finger :)

Kwakkie
27th August 2012, 09:18
Create the following class:

class uaWebPage : public QWebPage
{
public:
explicit uaWebPage(QObject * parent = 0) : QWebPage(parent) {}
virtual QString userAgentForUrl(const QUrl& url) const
{
Q_UNUSED(url);
return "Chrome/1.0";
}
};

And add this in your derived QWebView constructor (or after you create the default QWebView object, using the correct pointer)
setPage(new uaWebPage(this));

sebs
4th October 2012, 04:17
That little hack doesn't seem to work anymore!

Used it for the last 3-4 month and now Google must have changed the way they check for the userAgent.
Has anyone come up with a new solution that doesn't require to recompile QWebkit?

Kwakkie
4th October 2012, 08:35
Yes, google certainly changed something. I checked the change log and there is some indication about this. Not sure how to get it back working at this point (other than capturing the mouse events myself and calling the pan and zoom through a script). Might be the safest thing to do as any workaround might stop working in the future.

banjo51
7th October 2012, 13:56
Just have look to here (http://qt-project.org/forums/viewthread/11729)

I replace

return "Chrome/1.0";
with

return "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
and it works fine.

Didier