'How to open an HTML file in QtextBrowser
I have a ready-made HTML file, if it is opened through a browser, then a normal web page is displayed.
How can this HTML file be opened via the QTextBrowser widget so that structured information is also displayed in it as a web page?
I've tried something like this:
QFile file("/home/alex/data.html");
if(!file.open(QIODevice::ReadOnly))
QMessageBox::information(nullptr,"info",file.errorString());
QTextStream in(&file);
ui->textBrowser->setHtml(in.readAll());
but it didn't work out.
Solution 1:[1]
There are dedicated classes to display full webpages:
https://doc.qt.io/qt-5/qtwebengine-index.html
https://doc.qt.io/qt-5/qtwebengine-webenginewidgets-simplebrowser-example.html
In your case, QTextBrowser can "only" display rich text following HTML tags.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Yoruk |
