Péricles Lopes Machado Péricles Lopes Machado - 1 year ago 432
CSS Question

QWebView::settings()->setUserStyleSheetUrl() from QtWebKit to QtWebEngine?

I'm upgrading my code from Qt 5.5 to Qt 5.6, but I didn't find a way to port the following code:

QWebEngineView *qwebview = new QWebEngineView(this);

What is the best way to insert a user CSS using the new Qt Web Engine?

Answer Source

If you read here : Bug Report on QWebEngine, you'll see that :

The only opportunity to inject CSS code into the WebEngineView is using JavaScript. It would be nice to have an appropriate API for this and it could look like our already existing UserScripts API.

It seems pretty clear : you can't use the WebSettings anymore to insert CSS. Instead, you will have to use HTML/JavaScript to do that.

I don't know if it will help you, but here is an extract of what I have done .

In my .cpp :

m_pView = new QWebEngineView(this);

QUrl startURL = QUrl("path/to/index.html");


And in the index.html :

        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <!-- Many JS scripts here -->

        <link href="./css/style.css" rel="stylesheet">

    <body ng-app="myApp" >
      <div ui-view class="page"></div>

Hope that helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download