[PyQt] how to get text from QTextEdit document

Doug Bell dougb at bellz.org
Thu Apr 26 01:56:12 BST 2007


Paulino wrote:
> Hi,
> 
> I want to get the text from a QTextEdit widget into a list, to parse and 
> store in a database
> 
> I found this solution, but I think there is a cleaner way of doing it
> 
> 
>    def Imprimir(self):
>        doc = self.texto.document()
>        block = doc.begin()
>        lines = [ block.text() ]
>        for i in range( 1, doc.blockCount() ):
>            block = block.next()
>            lines.append( block.text() )
> 
> where :
> self.texto = QtGui.QTextEdit(self.widget)

How about:

   lines = unicode(self.texto.toPlainText()).split('\n')


Doug.


More information about the PyQt mailing list