Please nominate your Qt Champions for 2021!

QWebElement DOM Manipulation

  • I'm trying to add a default style to every rendered webpage in my browser. I've tried many different things and can't get the DOM to change. I'm using Qt 4.7.0 on Windows with VS. I believe the following should work, but the DOM doesn't get modified. Any thoughts?

    void QWebView::onLoadFinished(bool error)
    QWebElement style;
    style.setOuterXml("<style>*:focus{outline:1px solid red}</style>");
    style.setAttribute("type", "text/css");

  • Why not use QWebSettings::setUserStyleSheetUrl()? It seems that one is meant for setting a style sheet for your page. You can get a pointer to your QWebSettings instance from your QWebPage instance.

Log in to reply