Cristi
Cristi

Reputation: 730

Load html from resources file to QTextEdit

I am trying to do as follows:

QWidget* helpWidget = new QWidget();
QHBoxLayout* layout = new QHBoxLayout();
QTextEdit* textEdit = new QTextEdit();
textEdit->loadResource(QTextDocument::HtmlResource, QUrl("qrc:/help.html"));
textEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
layout->addWidget(textEdit);
helpWidget->setLayout(layout);

The resource file is as follows:

<RCC>
<qresource prefix="/">
    <file alias="help.html">../doc/index.html</file>
</qresource>
</RCC>

However the html file does not display in the QTextView. Can anyone help ?

Upvotes: 0

Views: 2574

Answers (1)

kefir500
kefir500

Reputation: 4404

QTextEdit::loadResource is a virtual method intended for a different purpose, see docs.

Instead you should manually read and set the HTML file contents:

QFile file(":/help.html");
file.open(QFile::ReadOnly | QFile::Text);
QTextStream stream(&file);
textEdit->setHtml(stream.readAll());

Upvotes: 4

Related Questions