[PyQt] binary file viewer with textEdit (PyQt)

Mark Summerfield list at qtrac.plus.com
Wed Jun 23 07:57:29 BST 2010

On 2010-06-22, sandokan wrote:
> Hi, hope you can help me. I am trying to view whole contents of binary 
> (PE file) in Qt TextEdit widget but still running into some problems 
> is the main problem). I have tried these two ways:
> 1) converting data using "codecs"
> s = codecs.open(self.filename,'rb','mbcs').read()
> self.ui.textEditAscii1.setPlainText(s)
> - this kind of works but is very slow....it take 10+ seconds to open  2kB
> file
> - reading is quite fast but displaying using setPlainText is tooo lazy
> - I have also tried to append file line by line which was even slower
> (hower I could at least process waiting events so the gui was not stuck
> during the file load) .....
> - also zeros (00h) are not displayed at all (not even represented by a
> white space)
> 2) displaying raw data which did not work at all:
> file = open(fd.getOpenFileName(),'rb').read()
> self.ui.textEditAscii1.setPlainText(file)
> print file
> - which prints file quite fine into console but displays only first ASCII
> characters (actualy it displays "MZ" only) into textEdit widget
> - using "self.ui.textEditAscii1.setPlainText(str(file))" did not change
> anything
> Do you guys have any hint how to display larger binary files (let say up 
> 10-20 MBs) in textEdit widget without waiting more than few seconds?

Hi Tom,

One thing that slows QTextEdit down is its sophisticated layout engine.
If you can live without that and use a QPlainTextEdit you should get
some speedup straightaway.

Mark Summerfield, Qtrac Ltd, www.qtrac.eu
    C++, Python, Qt, PyQt - training and consultancy
        "Advanced Qt Programming" - ISBN 0321635906

                            A true story...
 I ordered a Dell netbook with Ubuntu preinstalled. It arrived with no
 OS at all and Dell's "support" said the don't supply Ubuntu any more.
           Dell gave no apology, no solution, and no refund.
                     So I do *not* recommend Dell.

More information about the PyQt mailing list