Quote Originally Posted by claudio View Post
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

Qt Code:
  1. QString TextEdit::GrepTextLines(int startline, int stopline )
  2. {
  3. QStringList cuttextlist;
  4. cuttextlist.clear();
  5. int xli = 1;
  6. for ( QTextBlock block = document()->begin(); block.isValid(); block = block.next(), xli++) {
  7. if (xli == startline || xli > startline) {
  8. if (xli == stopline || xli < stopline) {
  9. cuttextlist.append(GrepLineFromTxBloc(block));
  10. ////////qDebug() << "### cat line GrepTextLines " << xli;
  11. }
  12. }
  13. }
  14. return cuttextlist.join("\n");
  15. }
  16.  
  17. QString TextEdit::GrepLineFromTxBloc( QTextBlock block )
  18. {
  19. QString linetext = "";
  20. if ( m_tabSpaces ) /* if tabulator key on to indent text ? */
  21. {
  22. int nbSpaces = tabStopWidth() / fontMetrics().width( " " );
  23. for (int i = 0; i<nbSpaces; i++) {
  24. linetext.append( " " );
  25. }
  26. linetext.append(block.text());
  27.  
  28. } else {
  29. linetext.append(block.text());
  30. }
  31.  
  32. return linetext;
  33. }
To copy to clipboard, switch view to plain text mode