Results 1 to 2 of 2

Thread: QWebView with .css, .js and images in a resource file...

  1. #1
    Join Date
    Sep 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X

    Default QWebView with .css, .js and images in a resource file...

    Hello, I have a .qrc file with a .css, a .js and some images in it that I would like to be able to include in a QWebView object.

    I have a string of HTML code with references to the aforementioned file types but when I call setHtml, all it does is display the text in their HTML tables without the styling or images that I want it to have.

    For this application, saving the webpage first is not appropriate, I am giving the user a preview of the page before they can save it.

    I am using 4.6 and any suggestions or example would be much appreciated, I did some searching first with minimal luck.

  2. #2
    Join Date
    Sep 2010
    Posts
    1
    Thanked 1 Time in 1 Post
    Qt products
    Platforms
    Unix/X11

    Default Re: QWebView with .css, .js and images in a resource file...

    Quote Originally Posted by sublimer View Post
    I have a string of HTML code with references to the aforementioned file types but when I call setHtml,
    You need to set a base url of 'qrc:/' when you call setHtml.

    here's a pyQt4 example

    Qt Code:
    1. import qrc_resources
    2. from PyQt4 import QtCore
    3. from PyQt4.QtWebKit import QWebView
    4.  
    5. wv = QWebView()
    6. wv.show()
    7. html = "<body><img src='mypicture.png' /></body>"
    8. wv.setHtml(html, QtCore.QUrl('qrc:/'))
    To copy to clipboard, switch view to plain text mode 

    incidentally, having a full path of 'qrc:/mypicture.png' within the html also works.

  3. The following user says thank you to rowinggolfer for this useful post:

    totem (23rd September 2010)

Similar Threads

  1. Loading images from resource files in webkit
    By redserpent7 in forum Qt Programming
    Replies: 1
    Last Post: 21st January 2015, 13:01
  2. Get images from a QWebView or QWebPage
    By redneon in forum Qt Programming
    Replies: 6
    Last Post: 21st January 2010, 09:03
  3. QWebView and resource manager
    By bunjee in forum Qt Programming
    Replies: 1
    Last Post: 12th December 2009, 06:48
  4. QWebView shows '?' instead of all images
    By doep in forum Qt Programming
    Replies: 2
    Last Post: 5th February 2009, 10:03
  5. Release build fails to find some resource images
    By MrGarbage in forum Installation and Deployment
    Replies: 3
    Last Post: 8th December 2007, 16:04

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.