How to display simple html file in Qt

paws picture paws · Dec 14, 2016 · Viewed 8.5k times · Source

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.

Answer

Elcan picture Elcan · Dec 14, 2016

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