Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQT Reading a text file

Tags:

python

qt

pyqt

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??

like image 956
Vii Avatar asked Dec 09 '22 23:12

Vii


1 Answers

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

Doesn't seem hard to me.

like image 95
Oleh Prypin Avatar answered Jan 31 '23 12:01

Oleh Prypin