Results 1 to 2 of 2

Thread: Set html <style> with QWebElement

  1. #1
    Join Date
    Dec 2010
    Posts
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Set html <style> with QWebElement

    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?

    Qt Code:
    1. void QWebView::onLoadFinished(bool error)
    2. {
    3. QWebElement style;
    4. style.setOuterXml("<style>*:focus{outline:1px solid red}</style>");
    5. style.setAttribute("type", "text/css");
    6. page()->mainFrame()->findFirstElement("head").appendInside(style);
    7. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2014
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Set html <style> with QWebElement

    Seems like it is not working... May be a bug.

    Yout need to get and load innerXml:

    Qt Code:
    1. void QWebView::onLoadFinished(bool error)
    2. {
    3. QWebElement style, head;
    4. style.setOuterXml("<style>*:focus{outline:1px solid red}</style>");
    5. style.setAttribute("type", "text/css");
    6. head = page()->mainFrame()->findFirstElement("head");
    7. head.setInnerXml(head.toInnerXml() + style.toOuterXml());
    8. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QWebElement available for QtScript, Marshaling/Template?
    By jasonknight in forum Qt Programming
    Replies: 2
    Last Post: 17th July 2012, 18:38
  2. Replies: 7
    Last Post: 14th June 2010, 03:42
  3. Dynamically create SVG with QWebElement
    By yawar in forum Qt Programming
    Replies: 0
    Last Post: 11th April 2010, 04:53
  4. Is there an HTML-style ImageMap available
    By importantman in forum Qt Programming
    Replies: 2
    Last Post: 27th May 2007, 06:50
  5. QLabel with HTML-style formatting docs?
    By Everall in forum Qt Programming
    Replies: 6
    Last Post: 7th February 2006, 21:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.