[PyQt] Log viewer

Frédéric frederic.mantegazza at gbiloba.org
Fri Jan 16 15:50:29 GMT 2009


Le 16/1/2009, "Mark Summerfield" <mark at qtrac.eu> a écrit:

>QPlainTextEdit is optimized for use as a log display and has
>appendHtml() and appendPlainText(). For Qt 4.3 or earlier use QTextEdit
>or QTextBrowser instead.

Thanks, Mark. So, you suggest I subclass QPlainTextEdit to add the
write() and flush() method (the logging handler mandatory interface),
and give that widget to the logger? Then, it won't have any parent, as
the dialog where I show the log is created on user request (and
destroyed as soon as the user close it)... Will it be possible to
reparent it on the fly in this dialog?

Is there a way to have something more model/view oriented? Some sort of
non-graphical object, the buffer (model), I can attached later to the
QPlainTextEdit (view)?

I would also like to be able to change the attributes (color, font...) of
each log entry, according to its level. This can be easily done in html,
but then, it will be harder, later, to get back the raw text (the user
can save the log from the log dialog). Is there any solution, here?

Here is how I did in PyGTK:

http://trac.gbiloba.org/papywizard/browser/branches/1.x/papywizard/view/logBuffer.py

The logBuffer is used in the log dialog:

http://trac.gbiloba.org/papywizard/browser/branches/1.x/papywizard/controller/loggerController.py

just by attaching it, with the Textview.set_buffer() method...

--
   Frédéric



More information about the PyQt mailing list