PDA

View Full Version : How to display text from file and program output in QTextEdit?



Iceman14
21st September 2012, 03:32
Hi everyone, I have a really simple problem that I could use some help with. I wrote a program which spell checks a plain text file and can do things like keep track of the most commonly used words / most commonly misspelled words. I've already implemented all of the functionality in a class called Dictionary. My problem is in displaying the contents of these files and some information obtained from the program in QTextEdit windows (and why we're using that rather than a normal display window, I don't know). I don't have any prior experience with GUI applications.

I don't need to do anything in the windows except display the contents of the file, with misspelled words in red, and show some program output in separate windows. I've been searching Google and reading the Qt documentation for about the past hour after finishing up the guts of the program but I can't find a solid tutorial for this, so if anyone could help me out I'd really appreciate the assistance.

Robbie
21st September 2012, 14:23
Perhaps the QSyntaxHighlighter might be your answer. There's a tutorial about how to use it. Check it out in the Qt Assistant or google it.

You can get the QTextDocument* directly from your QTextEdit, so the extra coding should be minimal on your part.

Iceman14
22nd September 2012, 02:18
Thanks for the response, I ended up using my display function to format the text in HTML for color.