
Originally Posted by
claudio
I have a QTextEdit and the user writes some text in it. How can I get the lines exactly the same way as they are displayed on the screen? I have to get every line start and line end - if possible the absolute text position *and* the y position of the line.
Thanks for any help!
Claudio
here is a sample to get line ...
from http://juffed.googlecode.com/svn/trunk/qedit/qtedit.cpp
my own first projekt
http://www.qt-apps.org/content/show....?content=59422
as editor now i use only http://www.riverbankcomputing.co.uk/...illa/index.php having all
QString TextEdit
::GrepTextLines(int startline,
int stopline
) {
cuttextlist.clear();
int xli = 1;
for ( QTextBlock block
= document
()->begin
(); block.
isValid(); block
= block.
next(), xli
++) { if (xli == startline || xli > startline) {
if (xli == stopline || xli < stopline) {
cuttextlist.append(GrepLineFromTxBloc(block));
////////qDebug() << "### cat line GrepTextLines " << xli;
}
}
}
return cuttextlist.join("\n");
}
{
if ( m_tabSpaces ) /* if tabulator key on to indent text ? */
{
int nbSpaces = tabStopWidth() / fontMetrics().width( " " );
for (int i = 0; i<nbSpaces; i++) {
linetext.append( " " );
}
linetext.append(block.text());
} else {
linetext.append(block.text());
}
return linetext;
}
QString TextEdit::GrepTextLines(int startline, int stopline )
{
QStringList cuttextlist;
cuttextlist.clear();
int xli = 1;
for ( QTextBlock block = document()->begin(); block.isValid(); block = block.next(), xli++) {
if (xli == startline || xli > startline) {
if (xli == stopline || xli < stopline) {
cuttextlist.append(GrepLineFromTxBloc(block));
////////qDebug() << "### cat line GrepTextLines " << xli;
}
}
}
return cuttextlist.join("\n");
}
QString TextEdit::GrepLineFromTxBloc( QTextBlock block )
{
QString linetext = "";
if ( m_tabSpaces ) /* if tabulator key on to indent text ? */
{
int nbSpaces = tabStopWidth() / fontMetrics().width( " " );
for (int i = 0; i<nbSpaces; i++) {
linetext.append( " " );
}
linetext.append(block.text());
} else {
linetext.append(block.text());
}
return linetext;
}
To copy to clipboard, switch view to plain text mode
Bookmarks