[PyQt] Re: how to append to a document? argghhhhh!

inhahe inhahe at gmail.com
Thu Oct 8 09:00:12 BST 2009


I figured out the problem with everything coming in reverse order.  i needed
movePosition instead of setPosition.  that seems to fix the color issue
also. i guess it's working fine so far, thanks anyway!

On Thu, Oct 8, 2009 at 3:47 AM, inhahe <inhahe at gmail.com> wrote:

> hello, I'm trying to make a couple of functions that add lines to the end
> of a QTextEdit window.  one to add html and one to add text.  it's not
> working and i can't figure out why or how to get around it.  it doesn't seem
> to make any sense.
> here's my code.
>
>   def addline(self, text):                                        #for
> plain text
>     c = QTextCursor(self.output.document())
>     c.setPosition(c.End)
>     c.insertHtml('<font color="green">')
>     c = QTextCursor(self.output.document())
>     c.setPosition(c.End)
>     stb = self.vs.value() == self.vs.maximum()
>     if self.output.toPlainText():
>       c.insertText('\n'+text)
>     else:
>       c.insertText(text)
>     if stb:
>       self.vs.setValue(self.vs.maximum())
>     c = QTextCursor(self.output.document())
>     c.setPosition(c.End)
>     c.insertHtml('</font>')
>
>
>   def addlinef(self, html):                            #for html
>     c = QTextCursor(self.output.document())
>     c.setPosition(c.End)
>     stb = self.vs.value() == self.vs.maximum()
>     if self.output.toPlainText():
>       c.insertHtml("<br/>"+html)
>     else:
>       c.insertHtml(html)
>     if stb:
>       self.vs.setValue(self.vs.maximum())
>
> some of the "c = QTextCursor(self.output.document())" and some of the
>  "c.setPosition(c.End)" may be redundant; i put them there for defensive
> programming to try to get this thing working.
>
> the problems are
> 1. i can't get the plain text lines to show up green.
> 2. everything shows up in backward order. it's as if c.setPosition(c.End)
> has no effect.
>
> thx
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20091008/80b81918/attachment-0001.html


More information about the PyQt mailing list