Reputation: 47
I created my own Webbrowser with QtWebEngine. Now I would like to set the User Agent with this->page()->profile()->setHttpUserAgent(USER_AGENT);
. This works well for the main view.
If i create a new myWebEngineView
inside the methode createWindow
of myWebEngineView
the User Agent will be the default User Agent of QtWebEngine.
myWebEngineView
is a subclass of QWebEngineView
.
How can I set the User Agent for all views?
Upvotes: 1
Views: 625
Reputation: 628
You can set the user agent in the newly created window again:
QWebEngineView* WebEngineView::createWindow( QWebEnginePage::WebWindowType type ) {
QWebEngineView* view = createView(); // your function to create a new tab or sth like this
view->page()->profile()->setHttpUserAgent( "" );
view->page()->profile()->setHttpUserAgent( "Mozilla/5.0( YOUR USER AGENT )" );
return view;
}
The user agent needs to be set twice, else its not transferred to the pages, see also ProfileAdapter::setHttpUserAgent(const QString &userAgent).
Upvotes: 1