Reputation: 430
I'm trying to create an HTML, CSS, and JavaScript editor using Qt. The problem I keep running into is whenever I load an HTML file, the QTextEdit
will display it, but without any of the HTML tags, which I need. I've tried to set the text using several functions (when loading the file) toHtml()
, setText()
, and setDocument()
, but to no avail. Is there any way of doing this? Do I have to read the file line by line and insert it that way?
As an example of what's going on:
helloworld.html
<html>
hello world!
</html>
when loading in to QTextEdit
, it displays:
hello world!
I would like QTextEdit
to display:
<html>
hello world!
</html>
Upvotes: 3
Views: 2114
Reputation: 5817
If you are not interested in the rich text capability of QTextEdit
you should have a look at QPlainTextEdit
. QPlainTextEdit
is optimized to handle large documents and to respond quickly to user input. It is based on the same technology and concepts as QTextEdit
, but is optimized for plain text handling.
If you for some reason still would want to use QTextEdit
, you can use the function QTextEdit::setPlainText(const QString&)
to insert plain text.
Upvotes: 3
Reputation: 40492
Use setPlainText
if you want to display your string as is.
Upvotes: 1