[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] QTextEdit: getting text with wordwrap newlines
From: David Cortesi <davecortesi () gmail ! com>
Date: 2014-04-26 15:47:36
Message-ID: CALyzANu3bB5z=_Z_XPkcM_m5j49yHaA-GreCYVMDOtb4gJkMZQ () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
>
> I have a QTextEdit which has word wrap enabled. I would like to get the
> text data but have the newlines from the word wrap as well. I basically
> need the text exactly as it appears to the user, rather than the one long
> string from toPlainText(). Is there a way to do this?
>
One, there's a difference between PyQt4 and PyQt5 and between Python 2.x
and 3.x. In Qt4, toPlainText() returns a QString, and you should find
within it a Unicode paragraph separator, \u2021 I think, wherever there is
a physical line break.
In Qt5, Phil et.al. did away with QString entirely and just returns a
Python string, which in Python 2.x will be a unicode string and in Python
3.x, just a str because str is automatically unicode. But either way, I
believe the string value ought to have \n wherever there is a line break in
the editor. Does it not?
Two, look at the QTextBlock interface. Each physical (possibly wrapped)
line in the editor is a QTextBlock. You can ask the QTextDocument (NOT the
QTextEdit) for its .begin(), use QTextBlock.next() and iterate through the
document that way. Or you can ask the document to .findBlockXXXX and get a
starting block in various ways, and use .next() or .prior() to iterate from
that line.
[Attachment #5 (text/html)]
<div dir="ltr"><div><div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px \
solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">I have a QTextEdit which \
has word wrap enabled. I would like to get the text data but have the newlines from \
the word wrap as well. I basically need the text exactly as it appears to the user, \
rather than the one long string from toPlainText(). Is there a way to do this? \
<br></blockquote><br></div>One, there's a difference between PyQt4 and PyQt5 and \
between Python 2.x and 3.x. In Qt4, toPlainText() returns a QString, and you should \
find within it a Unicode paragraph separator, \u2021 I think, wherever there is a \
physical line break.<br>
<br>In Qt5, Phil <a href="http://et.al">et.al</a>. did away with QString entirely and \
just returns a Python string, which in Python 2.x will be a unicode string and in \
Python 3.x, just a str because str is automatically unicode. But either way, I \
believe the string value ought to have \n wherever there is a line break in the \
editor. Does it not?<br>
<br></div>Two, look at the QTextBlock interface. Each physical (possibly wrapped) \
line in the editor is a QTextBlock. You can ask the QTextDocument (NOT the QTextEdit) \
for its .begin(), use QTextBlock.next() and iterate through the document that way. Or \
you can ask the document to .findBlockXXXX and get a starting block in various ways, \
and use .next() or .prior() to iterate from that line.<br>
<br></div>
[Attachment #6 (text/plain)]
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic