[PyQt] Access to lines of text on textEdit.

Algis Kabaila akabaila at pcug.org.au
Tue Sep 14 08:48:47 BST 2010


> On Tuesday 14 September 2010, 01:54:01 Algis Kabaila wrote:
> > Is it possible to access lines of text in a textEdit?  If so how can I
> > find information about it?

On Tuesday 14 September 2010 10:09:10 Hans-Peter Jansen wrote:
> Depending on document type, try this:
> 
> 	document().findBlockByLineNumber(lineNumber).text()
> 
> Pete

On Tuesday 14 September 2010 12:24:52 Henning Schröder wrote:
> If you enter findBlockByLineNumber in Qt Assistant you will see that
> this method  belongs to a QTextDocument object and returns a
> QTextBlock object QTextEdit has a method called "document()" which
> returns a QTextDocument.
> 
> Henning

In summary, the i-th line is returned by the following

line = self.textEdit.document().findBlockByLineNumber(i).text(),

which at least in part is identical to what Hans-Peter told me to do. Hennings 
advice to look up Qt Assistant was an invaluable help.  Thank you both.

Al.
-- 
OldAl
akabaila at pcug.org.au


More information about the PyQt mailing list