Results 1 to 9 of 9

Thread: How to display a html page in qgraphicswebview

  1. #1
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default How to display a html page in qgraphicswebview

    Hi,
    I want to load a html page in qgraphicswebview.
    How do I do it?

    I tried with something like below
    QString path = "/Users/user/Desktop/tocSample/learnONNav.html";
    m_p_TB_WebView->setHtml(path);

    but it didn't work out.

    Kindly let me know how do I display the html in qgraphicswebview.

    Thanks in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to display a html page in qgraphicswebview

    setHtml() accepts the HTML of the page, not its file path. Have a look at setUrl().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: How to display a html page in qgraphicswebview

    m_p_TB_WebView.load(QUrl("File:/Users/user/Desktop/tocSample/learnONNav.html");

    I used something like this and the html page got load.
    But on click on the hyperlinks on this page, it navigates to browser(IE/Chrome) and not on the graphicwebview.

    Kindly let me know, how to make the hyperlink open on graphicwebview itself.

    Thanks

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to display a html page in qgraphicswebview

    This works fine for me:

    Qt Code:
    1. #include <QtWidgets>
    2. #include <QGraphicsWebView>
    3.  
    4. int main(int argc, char **argv) {
    5. QApplication app(argc, argv);
    6.  
    7. view.setScene(&scene);
    8. QGraphicsWebView *wv = new QGraphicsWebView;
    9. scene.addItem(wv);
    10. view.show();
    11. wv->setUrl(QUrl("http://www.google.com"));
    12. return app.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 

    So does this:

    Qt Code:
    1. #include <QtWidgets>
    2. #include <QGraphicsWebView>
    3.  
    4. int main(int argc, char **argv) {
    5. QApplication app(argc, argv);
    6.  
    7. view.setScene(&scene);
    8. QGraphicsWebView *wv = new QGraphicsWebView;
    9. scene.addItem(wv);
    10. view.show();
    11. QUrl url = QUrl::fromLocalFile(QFileInfo("page.html").absoluteFilePath());
    12. qDebug() << url.toString();
    13. wv->setUrl(url);
    14. return app.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 

    with page.html being:

    html Code:
    1. <html>
    2. <body>
    3. <div>Link: <a href="http://www.google.com">Google</a></div>
    4. </body>
    5. </html>
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: How to display a html page in qgraphicswebview

    Can somebody throw light on how to make use of setHtml() or setContent() for QGraphicsWebView.

    setUrl() is making use of file from local machine.

    I want it to take file from server or from anywhere else and not from local machine.


    Added after 53 minutes:


    void QGraphicsWebView::setContent ( const QByteArray & data, const QString & mimeType = QString(), const QUrl & baseUrl = QUrl() )

    I hope this function will suit my need as it sets the content of qgraphicswebview from the html

    Can someone provide a sample for this function.
    I searched a lot on net but couldn't find any for qgraphicswebview.
    Last edited by ejoshva; 11th February 2015 at 05:09.

  6. #6
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Question How to load a .html file onto QGraphicsWebView?

    I need to load a .html file onto QGraphicsWebView.
    If it's from a local machine, I could directly use
    SetUrl()

    But I dont want it be loaded from local machine. I want it to be loaded from the server or elsewhere.
    How can this be done in Qt.

    Thanks in Advance.

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to load a .html file onto QGraphicsWebView?

    Quote Originally Posted by ejoshva View Post
    I need to load a .html file onto QGraphicsWebView.
    If it's from a local machine, I could directly use
    SetUrl()

    But I dont want it be loaded from local machine. I want it to be loaded from the server or elsewhere.
    How can this be done in Qt.
    You already know: setUrl()

    Cheers,
    _

  8. #8
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: How to load a .html file onto QGraphicsWebView?

    By setUrl() , I am able to load the .html from local machine.
    I want to the load the .html file from server and not local machine.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to load a .html file onto QGraphicsWebView?

    So pass a URL of the file on the server.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. How to Communicate between Qt and a HTML page
    By AbinaThomas in forum Qt Programming
    Replies: 0
    Last Post: 27th August 2012, 07:50
  2. Replies: 0
    Last Post: 3rd March 2012, 08:46
  3. jump from one html page to another html page
    By RENOLD in forum Qt Programming
    Replies: 4
    Last Post: 10th February 2012, 04:41
  4. Html page Display in QWebView
    By Tavit in forum Qt Programming
    Replies: 4
    Last Post: 10th July 2010, 15:39
  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.