Domanda

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>
È stato utile?

Soluzione

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.

Altri suggerimenti

Use setPlainText if you want to display your string as is.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top