qtqwebview

How to display simple html file in Qt


I'm looking for the easiest way to display a simple html file (just a long html-formatted text) inside the Qt dialog. Links, if any, should be opened in the external default system browser.


Solution

  • No need for a QWebView, use a QTextBrowser:

    #include <QTextBrowser>
    QTextBrowser *tb = new QTextBrowser(this);
    tb->setOpenExternalLinks(true);
    tb->setHtml(htmlString);
    

    also remember QT += widgets

    http://doc.qt.io/qt-5/qtextedit.html#html-prop

    http://doc.qt.io/qt-5/qtextbrowser.html#openExternalLinks-prop