[Qt-interest] deriving from QWebPage and web inspector capabilities
Crni Gorac
cgorac at gmail.com
Mon Mar 28 23:11:38 CEST 2011
In order to make it possible to send custom user agent string from my
browser-like application, I've created a class derived from QWebPage:
// ------------------------------------------------------------------------------
class WebPage : public QWebPage
{
public:
WebPage(QObject* parent = 0);
void setUserAgent(const QString& userAgent);
protected:
QString userAgentForUrl(const QUrl& url)const;
private:
QString m_userAgent;
};
WebPage::WebPage(QObject* parent)
: QWebPage(parent)
{
}
void WebPage::setUserAgent(const QString& userAgent)
{
m_userAgent = userAgent;
}
QString WebPage::userAgentForUrl(const QUrl& url)const
{
return m_userAgent;
}
// ------------------------------------------------------------------------------
and then I have following code in my main windows class constructor
(where m_webView is QWebView widget):
// ------------------------------------------------------------------------------
WebPage* webPage = new WebPage(this);
m_webView->setPage(webPage);
// ------------------------------------------------------------------------------
This works fine for the intended use, however now "Inspect" action is
not there any more in the right-click context menu of web view widget
(but "Reload" action is still there). I can see also that this action
is not there in the "browser" demo from Qt SDK. So - is there
anything to be changed so that this option is retained in this context
menu, when using web page class derived from QWebPage?
Also, related question: is it possible to have web page element
highlighted in QWebView, when mouse hovered over corresponding HTML
snippet in the Web Inspector console window (Google Chrome browser
makes that possible)?
Thanks.
More information about the Qt-interest-old
mailing list