PyQT Reading a text file


Question

I've been searching all over google and have found no solution, which is unbelievable! It should be simple. I'm trying to make my PyQT UI open a text file into a QTextBrowser or a QTextEdit.

But QTextEdit can't 'setSource' and QTextBrowser can not display anything but HTML, if I open the text file it doesn't have any of the paragraphing, it's all one line. This area will also display log files and I do NOT want my log files being output in html!

All I want to do is display the contents of a text file with plain text formatting. Why is this so stupidly hard??

1
4
6/13/2012 8:50:15 AM

Accepted Answer

text_edit = QPlainTextEdit()
...
text=open('file.txt').read()
text_edit.setPlainText(text)

Doesn't seem hard to me.

11
6/13/2012 8:59:40 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon