Results 1 to 3 of 3

Thread: How to display a html map in a Qt widget?

  1. #1
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default How to display a html map in a Qt widget?

    Qt Code:
    1. #include <QtCore>
    2. #include <QtGui>
    3. #include <QtWebKit>
    4.  
    5. int main (int argc, char * argv[])
    6. {
    7. QApplication app (argc, argv);
    8.  
    9. QUrl baseUrl = QUrl::fromLocalFile (QDir::current().absoluteFilePath ("file:///home/anisha/Desktop/ogmap.html"));
    10.  
    11. QString msg ("<html><body><img src='logo.png' /></body></html>");
    12.  
    13. QWebView *webView = new QWebView;
    14. webView->setHtml(msg, baseUrl);
    15.  
    16. webView->show();
    17. return app.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 

    This displays a small logo in the widget, nothing else. I am not interested in any logo.
    When I open that html file through Konqueror/Firefox, map gets displayed.
    What wrong am I doing here? I want the map to be displayed in that widget.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to display a html map in a Qt widget?

    You see a logo because that's the HTML you gave the QWebView to display. The HTML does not come from the base URL; that's where relative references in the HTML are resolved relative to.

    If you wanted the QWebview to show the ogmap.html file then you should give QWebView::setUrl() the URL to that file. At line 9 you take a roundabout path to try to create the file:// URL you started with Just:
    Qt Code:
    1. QUrl url("file:///home/anisha/Desktop/ogmap.html");
    2. // OR QUrl url = QUrl::fromLocalFile("/home/anisha/Desktop/ogmap.html");
    3. QWebView view;
    4. view.setUrl(url);
    5. view.show();
    To copy to clipboard, switch view to plain text mode 
    should do it.

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

    TheIndependentAquarius (5th July 2012)

  4. #3
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Re: How to display a html map in a Qt widget?

    Very thankful to you for that.
    So, I was using the wrong function: `setHtml`

    Your method worked flawlessly. :hattip:

Similar Threads

  1. Replies: 3
    Last Post: 1st April 2011, 14:02
  2. Html page Display in QWebView
    By Tavit in forum Qt Programming
    Replies: 4
    Last Post: 10th July 2010, 15:39
  3. Display '<' as HTML in QString
    By mclark in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2007, 21:43
  4. Is there a widget for display HTML files?
    By JeffJones in forum Newbie
    Replies: 6
    Last Post: 24th May 2007, 19:29
  5. Widget to display an HTML page ?
    By probine in forum Qt Tools
    Replies: 3
    Last Post: 11th October 2006, 18:55

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.